diff --git a/.gitignore b/.gitignore index 049ac48..1b663f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ logs/ *.pyc __pycache__/ -database.db \ No newline at end of file +database.db +settings.py \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api.py b/api.py index 1bfeeed..d2b626a 100644 --- a/api.py +++ b/api.py @@ -1,2 +1,67 @@ +import json +import datetime + +from request import Request, urlopen + +try: + from settings import USERNAME, PASSWORD +except: + USERNAME, PASSWORD = None, None + +API_URL = "https://www.planetromeo.com/api/v4/" + +class Attachment: + pass + +class Location: + def __init__(self, profile, name, country, timestamp=datetime.datetime.now()): + self.profile = profile + self.name = name + self.country = country + self.timestamp = timestamp + +class Profile: + def __init__(self, id, name): + self.id = id + self.name = name + +class Message: + def __init__(self, sender, recipient, id, date, text, attachments=[]): + self.sender = sender + self.recipient = recipient + self.id = id + self.date = date + self.text = text + self.attachments = attachments + + @classmethod + def from_dict(cls, message): + cls(message["from"], message["to"], message["id"], message["date"], message["text"], [Attachment.from_dict(attachment) for attachment in message["attachments"]]) + class RomeoAPI: - pass \ No newline at end of file + def __init__(self, login=True, username=USERNAME, password=PASSWORD): + if login: + self.login(username, password) + + def login(self, username, password): + payload = {"username": USERNAME, "password": PASSWORD, "keep_login": True} + response = urlopen(Request(API_URL + "session?lang=en"), json.dumps(payload).encode("utf-8")) + data = json.load(response) + self.session = data + + def build_headers(self, additional={}): + headers = { + "X-Api-Key": "vuEp8o93b34CxUCljSMFEdhI70qDWtuk", + "X-Session-Id": self.session["session_id"] + } + + for key, value in additional: + headers["key"] = value + + return headers + + def messages(self, count=4096): + headers = self.build_headers() + response = urlopen(Request(API_URL + "messages?lang=en&length=%i" % count, headers=headers)) + data = json.load(response) + print(data) \ No newline at end of file diff --git a/apidoc/get_headers.md b/apidoc/get_headers.md new file mode 100644 index 0000000..8fcce6c --- /dev/null +++ b/apidoc/get_headers.md @@ -0,0 +1,5 @@ +# Default headers for GET requests: + +* X-Api-Key: vuEp8o93b34CxUCljSMFEdhI70qDWtuk (seems to be hard-coded) +* X-Site: planetromeo (might not be necessary, leaving it in anyway) +* X-Session-Id: SESSION_ID (from login) \ No newline at end of file diff --git a/apidoc/images.md b/apidoc/images.md index ab47522..95e4e25 100644 --- a/apidoc/images.md +++ b/apidoc/images.md @@ -1 +1,5 @@ +Method: GET + +Headers: Probably none (?) + Endpoint: https://www.planetromeo.com/img/usr/original/0x0/URL_TOKEN.jpg (where URL_TOKEN is from the message object) \ No newline at end of file diff --git a/apidoc/login.md b/apidoc/login.md index 32b5cff..0d65f7c 100644 --- a/apidoc/login.md +++ b/apidoc/login.md @@ -1,5 +1,9 @@ +Method: POST + Endpoint: https://www.planetromeo.com/api/v4/session?lang=en Payload: {"username":"LOGIN_USER","password":"LOGIN_PASSWORD","keep_login":false} -Sample Response: {"user_id":"USER_ID","username":"LOGIN_USER","session_id":"SESSION_ID","online_status":"ONLINE","is_plus":true,"is_free_plus":false,"payment_group":"A","confirmed_account":true} \ No newline at end of file +Headers: X-Api-Key + +Sample Response: {"user_id":"USER_ID","username":"LOGIN_USER","session_id":"SESSION_ID","online_status":"ONLINE","is_plus":true,"is_free_plus":false,"payment_group":"A","confirmed_account":true, "login_auth_token": "AUTH_TOKEN"} \ No newline at end of file diff --git a/apidoc/messages.md b/apidoc/messages.md index afca7fd..c09244f 100644 --- a/apidoc/messages.md +++ b/apidoc/messages.md @@ -1,10 +1,10 @@ +Method: GET + Endpoint: https://www.planetromeo.com/api/v4/messages?lang=en&length=MESSAGES_COUNT Headers: -* X-Api-Key: vuEp8o93b34CxUCljSMFEdhI70qDWtuk (seems to be hard-coded) -* X-Site: planetromeo (might not be necessary, leaving it in anyway) -* X-Session-Id: SESSION_ID (from login) +Default GET headers Sample response: diff --git a/apidoc/profiles.md b/apidoc/profiles.md new file mode 100644 index 0000000..a2de624 --- /dev/null +++ b/apidoc/profiles.md @@ -0,0 +1,50 @@ +Method: GET + +Endpoint: https://www.planetromeo.com/api/v4/profiles/list?lang=en&ids[]=(Comma separated list of user IDs)&expand=*.(interactions)&pick=*.(id,name,interactions,online_status,location,preview_pic) + +Headers: + +Default GET headers + +Sample response: + +[ + { + "id":"USER_ID", + "name":"USER_NICK", + "interactions":{ + "id":"USER_ID", + "interactions":[ + "BLOCK_PROFILE", + "GRANT_ALBUM_ACCESS", + "POST_REVIEW", + "REACT_TO_PICTURES", + "REQUEST_ALBUM_ACCESS", + "SEND_ANDROID_INAPP_GIFT", + "SEND_FOOTPRINT", + "SEND_GIFT", + "SEND_LINK_REQUEST", + "SEND_MESSAGE", + "VISIT_PROFILE" + ] (= list of allowed interactions with that user) + }, + "online_status":"ONLINE_STATUS", + "location":{ + "name":"LOCATION_NAME", + "country":"LOCATION_COUNTRY", + "distance":LOCATION_DISTANCE (to self, int), + "sensor":SENSOR_STATUS (?, bool) + }, + "preview_pic":{ + "id":"PICTURE_ID", + "owner_id":"OWNER_ID" (probably always equals USER_ID), + "url_token":"PICTURE_URL_TOKEN", + "auth_token":"PICTURE_AUTH_TOKEN" (didn't see that used anywhere yet), + "width":PICTURE_WIDTH (int), + "height":PICTURE_HEIGHT (int), + "rating":"PICTURE_RATING", + "is_public":PICTURE_PUBLIC_STATUS (bool - probably always true for preview pics) + } + }, + (more profiles) +] \ No newline at end of file diff --git a/http.py b/http.py deleted file mode 100644 index 3d41a36..0000000 --- a/http.py +++ /dev/null @@ -1,6 +0,0 @@ -from urllib.request import Request as UrllibRequest - -class Request(UrllibRequest): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.headers["user-agent"] = "romeotools (https://kumig.it/kumitterer/romeotools)" \ No newline at end of file diff --git a/request.py b/request.py new file mode 100644 index 0000000..4a189fc --- /dev/null +++ b/request.py @@ -0,0 +1,8 @@ +from urllib.request import Request as UrllibRequest, urlopen + +class Request(UrllibRequest): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.headers["user-agent"] = "romeotools (https://kumig.it/kumitterer/romeotools)" + self.headers["X-Api-Key"] = "vuEp8o93b34CxUCljSMFEdhI70qDWtuk" + self.headers["Content-Type"] = "application/json" \ No newline at end of file