Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions server/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@





]


render = web.template.render(pth+'templ/',cache=True)
render = web.template.render(f'{pth}templ/', cache=True)
Comment on lines -47 to +52
Copy link
Author

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:



class settings:
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function login.POST refactored with the following changes:

return json.dumps({'token':l,'login':True})
else:
return json.dumps({'token':'','login':False})
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_json.GET refactored with the following changes:

return json.dumps(d)
except:
return json.dumps({'all':0})
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function images.GET refactored with the following changes:



app = web.application(urls, globals())
Expand Down
64 changes: 31 additions & 33 deletions server/insta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pretty_date refactored with the following changes:



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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function login refactored with the following changes:

r = s.get('https://www.instagram.com/')
s.headers.update({'X-CSRFToken': r.cookies['csrftoken']})
time.sleep(3 * random.random())
Expand All @@ -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:
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function like refactored with the following changes:




Expand Down
22 changes: 11 additions & 11 deletions server_bottle/bottle_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function login refactored with the following changes:

return json.dumps({'token':l,'login':True})
else:
return json.dumps({'token':'','login':False})
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_json refactored with the following changes:


return json.dumps(d)
except:
Expand All @@ -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()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function data refactored with the following changes:




Expand Down
62 changes: 30 additions & 32 deletions server_bottle/insta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pretty_date refactored with the following changes:



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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function login refactored with the following changes:

r = s.get('https://www.instagram.com/')
s.headers.update({'X-CSRFToken': r.cookies['csrftoken']})
time.sleep(3 * random.random())
Expand All @@ -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:
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function like refactored with the following changes:




Expand Down