Implement login and message retrieval
Make classes for objects
This commit is contained in:
parent
b2660a7e03
commit
7228fc9074
10 changed files with 143 additions and 12 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
logs/
|
||||
*.pyc
|
||||
__pycache__/
|
||||
database.db
|
||||
database.db
|
||||
settings.py
|
0
__init__.py
Normal file
0
__init__.py
Normal file
67
api.py
67
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
|
||||
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)
|
5
apidoc/get_headers.md
Normal file
5
apidoc/get_headers.md
Normal file
|
@ -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)
|
|
@ -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)
|
|
@ -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}
|
||||
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"}
|
|
@ -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:
|
||||
|
||||
|
|
50
apidoc/profiles.md
Normal file
50
apidoc/profiles.md
Normal file
|
@ -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)
|
||||
]
|
6
http.py
6
http.py
|
@ -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)"
|
8
request.py
Normal file
8
request.py
Normal file
|
@ -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"
|
Loading…
Reference in a new issue