-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.py
131 lines (106 loc) · 6.69 KB
/
lib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import urllib
import sys
import json
from workflow import Workflow, ICON_WEB, web
def search_user_logs(username):
"""
search current user logs/content
"""
url = "https://www.analogue.app/api/logs"
params = dict(username=username, tag="", limit=10, offset=0, collection=True)
r = web.get(url, params)
# Workflow will catch this and show it to the user
r.raise_for_status()
result = r.json()["data"]
return result
def search_analogue(query):
"""
Search all of analogue for a specific piece of content
"""
url = "https://pysrv.now.sh/analogue/search"
# TODO: Get username via the env config or using auth
params = dict(q=query)
r = web.get(url, params)
# throw an error if request failed
# Workflow will catch this and show it to the user
r.raise_for_status()
# Parse the JSON returned by pinboard and extract the posts
result = r.json()["hits"]
return result
def search_analogue_users(query):
"""
Search all of analogue for a specific piece of content
"""
url = "https://pysrv.now.sh/analogue/users"
params = dict(q=query)
r = web.get(url, params)
# throw an error if request failed
# Workflow will catch this and show it to the user
r.raise_for_status()
result = r.json()["hits"]
return result
def get_token(email, password):
"""
Get user token for API calls
"""
r = web.post(
url="https://www.analogue.app/api/users/login",
params=None,
headers={
"Connection": "keep-alive",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36",
"Content-Type": "application/json",
"Accept": "*/*",
"Origin": "https://www.analogue.app",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
"Referer": "https://www.analogue.app/login",
"Accept-Language": "en-US,en;q=0.9",
"Cookie": "ajs_group_id=null; ajs_anonymous_id=%22453c9e9b-20d9-464b-9b2f-544d08c4517c%22; ajs_user_id=%228503%22; _lr_uf_-9zropr=1f5d3d9a-7af1-478a-af9a-9bdd499187e6; amplitude_idundefinedanalogue.app=eyJvcHRPdXQiOmZhbHNlLCJzZXNzaW9uSWQiOm51bGwsImxhc3RFdmVudFRpbWUiOm51bGwsImV2ZW50SWQiOjAsImlkZW50aWZ5SWQiOjAsInNlcXVlbmNlTnVtYmVyIjowfQ==; _lr_tabs_-9zropr%2Fanalogue={%22sessionID%22:0%2C%22recordingID%22:%224-6ccf0dab-5235-4d33-a78a-0693d0268674%22%2C%22lastActivity%22:1588357409717}; _lr_hb_-9zropr%2Fanalogue={%22heartbeat%22:1588357409717}; mp_42c2d87f255cdb53a9581d2596fe60d6_mixpanel=%7B%22distinct_id%22%3A%20%228503%22%2C%22%24device_id%22%3A%20%22171a213b18430e-0029530280115b-39687506-13c680-171a213b185a21%22%2C%22mp_lib%22%3A%20%22Segment%3A%20web%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%2C%22%24user_id%22%3A%20%228503%22%2C%22mp_name_tag%22%3A%20%22hughmil3s%40gmail.com%22%2C%22type%22%3A%20%22consumer%22%2C%22id%22%3A%20%228503%22%2C%22%24email%22%3A%20%22hughmil3s%40gmail.com%22%2C%22%24first_name%22%3A%20%22Hugh%22%2C%22%24last_name%22%3A%20%22A.%20Miles%20II%22%2C%22%24name%22%3A%20%22Hugh%20A.%20Miles%20II%22%2C%22%24username%22%3A%20%22hugh%22%7D; amplitude_id_4bf7a5f993ab7a9311ed9393614f20c5analogue.app=eyJkZXZpY2VJZCI6IjAwNDJmZGM2LTY0OTktNDY4Yi1hZjFhLTEzOTFjOTI5MGFiYVIiLCJ1c2VySWQiOiI4NTAzIiwib3B0T3V0IjpmYWxzZSwic2Vzc2lvbklkIjoxNTg4MzU2NTY1NzE2LCJsYXN0RXZlbnRUaW1lIjoxNTg4MzU3NDE5MTA2LCJldmVudElkIjoxNTAsImlkZW50aWZ5SWQiOjQ3LCJzZXF1ZW5jZU51bWJlciI6MTk3fQ==",
"Accept-Encoding": "gzip",
},
cookies=None,
files=None,
auth=None,
timeout=60,
allow_redirects=False,
stream=False,
data=json.dumps({"user": {"email": email, "password": password}}),
)
return r.json()["user"]["token"], r.json()["user"]["username"]
def add_log(log_url):
"""
Create a log
"""
url = urllib.quote(log_url)
r = web.post(
url="https://www.analogue.app/api/contents/parse?url={}".format(url),
params=None,
headers={
"authorization": "Token eyJhbGciOiJIUzI1NiJ9.eyJpZCI6ODUwMywiZXhwIjoxNTk0Nzg1MDY5fQ.qr9HFOlUUqNTV9WassFoVKUuS8fQ08aw05BmLaZzOUw",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36",
"Content-Type": "application/json",
"Accept": "*/*",
"Origin": "https://www.analogue.app",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
"Referer": "https://www.analogue.app/alfred",
"Accept-Language": "en-US,en;q=0.9",
"Cookie": "ajs_group_id=null; ajs_anonymous_id=%22453c9e9b-20d9-464b-9b2f-544d08c4517c%22; ajs_user_id=%228503%22; _lr_uf_-9zropr=1f5d3d9a-7af1-478a-af9a-9bdd499187e6; amplitude_idundefinedanalogue.app=eyJvcHRPdXQiOmZhbHNlLCJzZXNzaW9uSWQiOm51bGwsImxhc3RFdmVudFRpbWUiOm51bGwsImV2ZW50SWQiOjAsImlkZW50aWZ5SWQiOjAsInNlcXVlbmNlTnVtYmVyIjowfQ==; _lr_tabs_-9zropr%2Fanalogue={%22sessionID%22:0%2C%22recordingID%22:%224-6ccf0dab-5235-4d33-a78a-0693d0268674%22%2C%22lastActivity%22:1588357409717}; _lr_hb_-9zropr%2Fanalogue={%22heartbeat%22:1588357409717}; mp_42c2d87f255cdb53a9581d2596fe60d6_mixpanel=%7B%22distinct_id%22%3A%20%228503%22%2C%22%24device_id%22%3A%20%22171a213b18430e-0029530280115b-39687506-13c680-171a213b185a21%22%2C%22mp_lib%22%3A%20%22Segment%3A%20web%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%2C%22%24user_id%22%3A%20%228503%22%2C%22mp_name_tag%22%3A%20%22hughmil3s%40gmail.com%22%2C%22type%22%3A%20%22consumer%22%2C%22id%22%3A%20%228503%22%2C%22%24email%22%3A%20%22hughmil3s%40gmail.com%22%2C%22%24first_name%22%3A%20%22Hugh%22%2C%22%24last_name%22%3A%20%22A.%20Miles%20II%22%2C%22%24name%22%3A%20%22Hugh%20A.%20Miles%20II%22%2C%22%24username%22%3A%20%22hugh%22%7D; amplitude_id_4bf7a5f993ab7a9311ed9393614f20c5analogue.app=eyJkZXZpY2VJZCI6IjAwNDJmZGM2LTY0OTktNDY4Yi1hZjFhLTEzOTFjOTI5MGFiYVIiLCJ1c2VySWQiOiI4NTAzIiwib3B0T3V0IjpmYWxzZSwic2Vzc2lvbklkIjoxNTg4MzU2NTY1NzE2LCJsYXN0RXZlbnRUaW1lIjoxNTg4MzU3NDE5MTA2LCJldmVudElkIjoxNTAsImlkZW50aWZ5SWQiOjQ3LCJzZXF1ZW5jZU51bWJlciI6MTk3fQ==",
"Accept-Encoding": "gzip",
},
cookies=None,
files=None,
auth=None,
timeout=60,
allow_redirects=False,
stream=False,
data=json.dumps({}),
)
return "https://www.analogue.app/{}/{}/@{}".format(
r.json()["content"]["form"],
r.json()["content"]["slug"],
r.json()["log"]["user"]["username"],
)