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 #1

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
58 changes: 22 additions & 36 deletions .lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,25 @@ def get_page(usrname):
global resp_js
session = requests.session()
session.headers = {'User-Agent': random.choice(useragent)}
resp_js = session.get('https://www.instagram.com/'+usrname+'/?__a=1').text
resp_js = session.get(f'https://www.instagram.com/{usrname}/?__a=1').text
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_page refactored with the following changes:

return resp_js

def exinfo():

def xprint(xdict, text):
if xdict != {}:
print(f"{su} {re}most used %s :" % text)
i = 0
for key, val in xdict.items():
if len(mail) == 1:
if key in mail[0]:
continue
print(f" {gr}%s : {wh}%s" % (key, val))
i += 1
if i > 4:
break
print()
else:
pass

if xdict == {}:
return
print(f"{su} {re}most used %s :" % text)
i = 0
for key, val in xdict.items():
if len(mail) == 1 and key in mail[0]:
continue
print(f" {gr}%s : {wh}%s" % (key, val))
i += 1
if i > 4:
break
print()

Comment on lines -31 to +43
Copy link
Author

Choose a reason for hiding this comment

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

Function exinfo refactored with the following changes:

raw = find(resp_js)

mail = raw['email']
Expand All @@ -65,17 +63,15 @@ def xprint(xdict, text):
def user_info(usrname):

global total_uploads, is_private

resp_js = get_page(usrname)
js = json.loads(resp_js)
js = js['graphql']['user']

if js['is_private'] != False:
is_private = True

if js['edge_owner_to_timeline_media']['count'] > 12:
pass
else:

if js['edge_owner_to_timeline_media']['count'] <= 12:
Comment on lines -68 to +74
Copy link
Author

Choose a reason for hiding this comment

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

Function user_info refactored with the following changes:

total_uploads = js['edge_owner_to_timeline_media']['count']

usrinfo = {
Expand Down Expand Up @@ -112,7 +108,6 @@ def user_info(usrname):

def highlight_post_info(i):

postinfo = {}
Copy link
Author

Choose a reason for hiding this comment

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

Function highlight_post_info refactored with the following changes:

total_child = 0
child_img_list = []

Expand Down Expand Up @@ -156,9 +151,6 @@ def highlight_post_info(i):

child_img_list.append(img_info)

postinfo['imgs'] = child_img_list
postinfo['info'] = info

else:
info = {
'comments': js['edge_media_to_comment']['count'],
Expand Down Expand Up @@ -186,24 +178,18 @@ def highlight_post_info(i):
'is_video': js['is_video'],
'accessibility': js['accessibility_caption']
}

child_img_list.append(img_info)

postinfo['imgs'] = child_img_list
postinfo['info'] = info

return postinfo
return {'imgs': child_img_list, 'info': info}

def post_info():

if is_private != False:
print(f"{fa} {gr}cannot use -p for private accounts !\n")
sys.exit(1)

posts = []

for x in range(total_uploads):
posts.append(highlight_post_info(x))

posts = [highlight_post_info(x) for x in range(total_uploads)]
Comment on lines -202 to +192
Copy link
Author

Choose a reason for hiding this comment

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

Function post_info refactored with the following changes:


for x in range(len(posts)):
# get 1 item from post list
Expand Down
2 changes: 1 addition & 1 deletion .lib/check_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def validate_mail(mail):
regex = r"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$"
match = r.match(regex, mail)
if match == None:
if match is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function validate_mail refactored with the following changes:

print('regex : fail')
else:
print('regex : success')
Expand Down
9 changes: 3 additions & 6 deletions .lib/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# 30-33, 48-50, 94-96, 195-210

def urlshortner(url):
data = requests.get("http://tinyurl.com/api-create.php?url=" + url)
data = requests.get(f"http://tinyurl.com/api-create.php?url={url}")
Copy link
Author

Choose a reason for hiding this comment

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

Function urlshortner refactored with the following changes:

return data.text

def write(stri):
Expand All @@ -30,14 +30,11 @@ def write(stri):

def sort_list(xlist):
with_count = dict(collections.Counter(xlist))
output = {k: v for k, v in sorted(with_count.items(), reverse=True, key=lambda item: item[1])}
return output
return dict(sorted(with_count.items(), reverse=True, key=lambda item: item[1]))
Copy link
Author

Choose a reason for hiding this comment

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

Function sort_list refactored with the following changes:


def find(stri):
exinfo = {}
email = r.findall(r"[_a-z0-9-\.]+[@@]{1}[a-z0-9]+\.[a-z0-9]+", stri.lower())
exinfo['email'] = email

exinfo = {'email': email}
Copy link
Author

Choose a reason for hiding this comment

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

Function find refactored with the following changes:

#(?:^|\s)([#|@]{1}[_a-zA-Z0-9\.\+-]+)
tags = r.findall(r"[##]{1}([_a-zA-Z0-9\.\+-]+)", stri)
exinfo['tags'] = tags
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/env python3

import os, sys
sys.path.append(os.getcwd()+"/.lib/")
sys.path.append(f"{os.getcwd()}/.lib/")
Copy link
Author

Choose a reason for hiding this comment

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

Lines 4-12 refactored with the following changes:

import argparse
from api import *

ap = argparse.ArgumentParser()
ap.add_argument("-u", "--user", required=True, help="username of account to scan")
ap.add_argument("-p", "--post", action="store_true", help="image info of user uploads")
args = vars(ap.parse_args())

os.system("clear")

if args['user']:
Expand Down