-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,12 +44,12 @@ | |
|
||
|
||
|
||
|
||
|
||
] | ||
|
||
|
||
render = web.template.render(pth+'templ/',cache=True) | ||
render = web.template.render(f'{pth}templ/', cache=True) | ||
|
||
|
||
class settings: | ||
|
@@ -59,10 +59,9 @@ def GET(self,sets,is_new): | |
return render.settings(sets=int(sets),is_new=int(is_new)) | ||
class login: | ||
def POST(self): | ||
web.header('Access-Control-Allow-Origin', '*') | ||
web.header('Access-Control-Allow-Origin', '*') | ||
i=web.input() | ||
l=insta.login(i.login,i.passw) | ||
if l: | ||
if l := insta.login(i.login, i.passw): | ||
Comment on lines
-62
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return json.dumps({'token':l,'login':True}) | ||
else: | ||
return json.dumps({'token':'','login':False}) | ||
|
@@ -88,15 +87,15 @@ def GET(self,token,numb): | |
ulikes.append(x[4]) | ||
dates.append(x[5]) | ||
|
||
d={} | ||
d['likes']=likes | ||
d['all']=len(likes) | ||
d['names']=names | ||
d['texts']=texts | ||
d['lids']=lids | ||
d['ulikes']=ulikes | ||
d['dates']=dates | ||
|
||
d = { | ||
'likes': likes, | ||
'all': len(likes), | ||
'names': names, | ||
'texts': texts, | ||
'lids': lids, | ||
'ulikes': ulikes, | ||
'dates': dates, | ||
} | ||
Comment on lines
-91
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return json.dumps(d) | ||
except: | ||
return json.dumps({'all':0}) | ||
|
@@ -105,7 +104,7 @@ class images: | |
def GET(self,token,numb): | ||
web.header('Access-Control-Allow-Origin', '*') | ||
web.header('Content-type','image/png') | ||
return open(pth+'data/'+token+'/'+str(numb)+'.png','rb').read() | ||
return open(f'{pth}data/{token}/{str(numb)}.png', 'rb').read() | ||
Comment on lines
-108
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
app = web.application(urls, globals()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,41 +32,41 @@ def pretty_date(time=False): | |
if second_diff < 10: | ||
return "just now" | ||
if second_diff < 60: | ||
return str(second_diff) + " seconds ago" | ||
return f"{str(second_diff)} seconds ago" | ||
if second_diff < 120: | ||
return "a minute ago" | ||
if second_diff < 3600: | ||
return str(second_diff / 60) + " minutes ago" | ||
return f"{str(second_diff / 60)} minutes ago" | ||
if second_diff < 7200: | ||
return "an hour ago" | ||
if second_diff < 86400: | ||
return str(second_diff / 3600) + " hours ago" | ||
return f"{str(second_diff / 3600)} hours ago" | ||
if day_diff == 1: | ||
return "Yesterday" | ||
if day_diff < 7: | ||
return str(day_diff) + " days ago" | ||
return f"{str(day_diff)} days ago" | ||
if day_diff < 31: | ||
return str(day_diff / 7) + " weeks ago" | ||
return f"{str(day_diff / 7)} weeks ago" | ||
if day_diff < 365: | ||
return str(day_diff / 30) + " months ago" | ||
return str(day_diff / 365) + " years ago" | ||
return f"{str(day_diff / 30)} months ago" | ||
return f"{str(day_diff / 365)} years ago" | ||
Comment on lines
-35
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def login(username,password): | ||
s = requests.Session() | ||
s.cookies.update({'sessionid': '', 'mid': '', 'ig_pr': '1','ig_vw': '1920', 'csrftoken': '','s_network': '', 'ds_user_id': ''}) | ||
login_post = {'username': username,'password': password} | ||
s.headers.update({'Accept-Encoding': 'gzip, deflate', | ||
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', | ||
'Connection': 'keep-alive', | ||
'Content-Length': '0', | ||
'Host': 'www.instagram.com', | ||
'Origin': 'https://www.instagram.com', | ||
'Referer': 'https://www.instagram.com/', | ||
'User-Agent': ("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 " | ||
"(KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36"), | ||
'X-Instagram-AJAX': '1', | ||
'X-Requested-With': 'XMLHttpRequest'}) | ||
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', | ||
'Connection': 'keep-alive', | ||
'Content-Length': '0', | ||
'Host': 'www.instagram.com', | ||
'Origin': 'https://www.instagram.com', | ||
'Referer': 'https://www.instagram.com/', | ||
'User-Agent': ("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 " | ||
"(KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36"), | ||
'X-Instagram-AJAX': '1', | ||
'X-Requested-With': 'XMLHttpRequest'}) | ||
Comment on lines
-60
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
r = s.get('https://www.instagram.com/') | ||
s.headers.update({'X-CSRFToken': r.cookies['csrftoken']}) | ||
time.sleep(3 * random.random()) | ||
|
@@ -80,9 +80,7 @@ def login(username,password): | |
r = s.get('https://www.instagram.com/') | ||
finder = r.text | ||
if username not in finder :return False | ||
d={} | ||
for x in login.cookies.keys(): | ||
d[x]=login.cookies[x] | ||
d = {x: login.cookies[x] for x in login.cookies.keys()} | ||
try: | ||
os.mkdir(pth+csrftoken) | ||
except: | ||
|
@@ -97,20 +95,20 @@ def like(token,lid): | |
s = requests.Session() | ||
s.cookies.update(c) | ||
s.headers.update({'Accept-Encoding': 'gzip, deflate', | ||
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', | ||
'Connection': 'keep-alive', | ||
'Content-Length': '0', | ||
'Host': 'www.instagram.com', | ||
'Origin': 'https://www.instagram.com', | ||
'Referer': 'https://www.instagram.com/', | ||
'User-Agent': ("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 " | ||
"(KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36"), | ||
'X-Instagram-AJAX': '1', | ||
'X-Requested-With': 'XMLHttpRequest'}) | ||
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', | ||
'Connection': 'keep-alive', | ||
'Content-Length': '0', | ||
'Host': 'www.instagram.com', | ||
'Origin': 'https://www.instagram.com', | ||
'Referer': 'https://www.instagram.com/', | ||
'User-Agent': ("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 " | ||
"(KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36"), | ||
'X-Instagram-AJAX': '1', | ||
'X-Requested-With': 'XMLHttpRequest'}) | ||
s.headers.update({'content-type':'application/x-www-form-urlencoded'}) | ||
s.headers.update({'path':'/web/likes/'+str(lid)+'/like/'}) | ||
s.headers.update({'x-csrftoken':c['csrftoken']}) | ||
re=s.post('https://www.instagram.com/web/likes/%s/like/'%(lid)) | ||
s.headers.update({'path': f'/web/likes/{str(lid)}/like/'}) | ||
s.headers.update({'x-csrftoken':c['csrftoken']}) | ||
re = s.post(f'https://www.instagram.com/web/likes/{lid}/like/') | ||
Comment on lines
-100
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,7 @@ def login(): | |
response.headers['Access-Control-Allow-Origin'] = '*' | ||
login = request.forms.get('login') | ||
passw = request.forms.get('passw') | ||
l=insta.login(login,passw) | ||
if l: | ||
if l := insta.login(login, passw): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return json.dumps({'token':l,'login':True}) | ||
else: | ||
return json.dumps({'token':'','login':False}) | ||
|
@@ -70,14 +69,15 @@ def get_json(token,numb): | |
ulikes.append(x[4]) | ||
dates.append(x[5]) | ||
|
||
d={} | ||
d['likes']=likes | ||
d['all']=len(likes) | ||
d['names']=names | ||
d['texts']=texts | ||
d['lids']=lids | ||
d['ulikes']=ulikes | ||
d['dates']=dates | ||
d = { | ||
'likes': likes, | ||
'all': len(likes), | ||
'names': names, | ||
'texts': texts, | ||
'lids': lids, | ||
'ulikes': ulikes, | ||
'dates': dates, | ||
} | ||
Comment on lines
-73
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
return json.dumps(d) | ||
except: | ||
|
@@ -87,7 +87,7 @@ def get_json(token,numb): | |
def data(token,numb): | ||
response.headers['Access-Control-Allow-Origin'] = '*' | ||
response.content_type = 'image/png' | ||
return open(pth+'data/'+token+'/'+str(numb)+'.png','rb').read() | ||
return open(f'{pth}data/{token}/{str(numb)}.png', 'rb').read() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,41 +32,41 @@ def pretty_date(time=False): | |
if second_diff < 10: | ||
return "just now" | ||
if second_diff < 60: | ||
return str(second_diff) + " seconds ago" | ||
return f"{str(second_diff)} seconds ago" | ||
if second_diff < 120: | ||
return "a minute ago" | ||
if second_diff < 3600: | ||
return str(second_diff / 60) + " minutes ago" | ||
return f"{str(second_diff / 60)} minutes ago" | ||
if second_diff < 7200: | ||
return "an hour ago" | ||
if second_diff < 86400: | ||
return str(second_diff / 3600) + " hours ago" | ||
return f"{str(second_diff / 3600)} hours ago" | ||
if day_diff == 1: | ||
return "Yesterday" | ||
if day_diff < 7: | ||
return str(day_diff) + " days ago" | ||
return f"{str(day_diff)} days ago" | ||
if day_diff < 31: | ||
return str(day_diff / 7) + " weeks ago" | ||
return f"{str(day_diff / 7)} weeks ago" | ||
if day_diff < 365: | ||
return str(day_diff / 30) + " months ago" | ||
return str(day_diff / 365) + " years ago" | ||
return f"{str(day_diff / 30)} months ago" | ||
return f"{str(day_diff / 365)} years ago" | ||
Comment on lines
-35
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def login(username,password): | ||
s = requests.Session() | ||
s.cookies.update({'sessionid': '', 'mid': '', 'ig_pr': '1','ig_vw': '1920', 'csrftoken': '','s_network': '', 'ds_user_id': ''}) | ||
login_post = {'username': username,'password': password} | ||
s.headers.update({'Accept-Encoding': 'gzip, deflate', | ||
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', | ||
'Connection': 'keep-alive', | ||
'Content-Length': '0', | ||
'Host': 'www.instagram.com', | ||
'Origin': 'https://www.instagram.com', | ||
'Referer': 'https://www.instagram.com/', | ||
'User-Agent': ("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 " | ||
"(KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36"), | ||
'X-Instagram-AJAX': '1', | ||
'X-Requested-With': 'XMLHttpRequest'}) | ||
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', | ||
'Connection': 'keep-alive', | ||
'Content-Length': '0', | ||
'Host': 'www.instagram.com', | ||
'Origin': 'https://www.instagram.com', | ||
'Referer': 'https://www.instagram.com/', | ||
'User-Agent': ("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 " | ||
"(KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36"), | ||
'X-Instagram-AJAX': '1', | ||
'X-Requested-With': 'XMLHttpRequest'}) | ||
Comment on lines
-60
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
r = s.get('https://www.instagram.com/') | ||
s.headers.update({'X-CSRFToken': r.cookies['csrftoken']}) | ||
time.sleep(3 * random.random()) | ||
|
@@ -80,9 +80,7 @@ def login(username,password): | |
r = s.get('https://www.instagram.com/') | ||
finder = r.text | ||
if username not in finder :return False | ||
d={} | ||
for x in login.cookies.keys(): | ||
d[x]=login.cookies[x] | ||
d = {x: login.cookies[x] for x in login.cookies.keys()} | ||
try: | ||
os.mkdir(pth+csrftoken) | ||
except: | ||
|
@@ -97,20 +95,20 @@ def like(token,lid): | |
s = requests.Session() | ||
s.cookies.update(c) | ||
s.headers.update({'Accept-Encoding': 'gzip, deflate', | ||
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', | ||
'Connection': 'keep-alive', | ||
'Content-Length': '0', | ||
'Host': 'www.instagram.com', | ||
'Origin': 'https://www.instagram.com', | ||
'Referer': 'https://www.instagram.com/', | ||
'User-Agent': ("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 " | ||
"(KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36"), | ||
'X-Instagram-AJAX': '1', | ||
'X-Requested-With': 'XMLHttpRequest'}) | ||
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', | ||
'Connection': 'keep-alive', | ||
'Content-Length': '0', | ||
'Host': 'www.instagram.com', | ||
'Origin': 'https://www.instagram.com', | ||
'Referer': 'https://www.instagram.com/', | ||
'User-Agent': ("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 " | ||
"(KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36"), | ||
'X-Instagram-AJAX': '1', | ||
'X-Requested-With': 'XMLHttpRequest'}) | ||
s.headers.update({'content-type':'application/x-www-form-urlencoded'}) | ||
s.headers.update({'path':'/web/likes/'+str(lid)+'/like/'}) | ||
s.headers.update({'path': f'/web/likes/{str(lid)}/like/'}) | ||
s.headers.update({'x-csrftoken':c['csrftoken']}) | ||
re=s.post('https://www.instagram.com/web/likes/%s/like/'%(lid)) | ||
re = s.post(f'https://www.instagram.com/web/likes/{lid}/like/') | ||
Comment on lines
-100
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines
47-52
refactored with the following changes:use-fstring-for-concatenation
)