diff --git a/server/code.py b/server/code.py index 84b911f..5b19470 100644 --- a/server/code.py +++ b/server/code.py @@ -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): 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, + } 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() app = web.application(urls, globals()) diff --git a/server/insta.py b/server/insta.py index d7de7b1..eaed396 100644 --- a/server/insta.py +++ b/server/insta.py @@ -32,24 +32,24 @@ 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" def login(username,password): @@ -57,16 +57,16 @@ def login(username,password): 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'}) 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/') diff --git a/server_bottle/bottle_app.py b/server_bottle/bottle_app.py index 72df53e..94e0fce 100644 --- a/server_bottle/bottle_app.py +++ b/server_bottle/bottle_app.py @@ -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): 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, + } 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() diff --git a/server_bottle/insta.py b/server_bottle/insta.py index 9fb3972..62e9c78 100644 --- a/server_bottle/insta.py +++ b/server_bottle/insta.py @@ -32,24 +32,24 @@ 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" def login(username,password): @@ -57,16 +57,16 @@ def login(username,password): 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'}) 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/')