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

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented May 16, 2022

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from kaist May 16, 2022 07:42
Comment on lines -47 to +52


]


render = web.template.render(pth+'templ/',cache=True)
render = web.template.render(f'{pth}templ/', cache=True)
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:

Comment on lines -62 to +64
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):
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:

Comment on lines -91 to +98
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,
}
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:

Comment on lines -108 to +107
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 images.GET refactored with the following changes:

Comment on lines -35 to +52
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"
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:

Comment on lines -73 to +80
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,
}
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 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:

Comment on lines -35 to +52
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"
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:

Comment on lines -60 to +69
'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'})
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:

Comment on lines -100 to +111
'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/')
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:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented May 16, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.05%.

Quality metrics Before After Change
Complexity 7.48 ⭐ 7.45 ⭐ -0.03 👍
Method Length 95.67 🙂 94.29 🙂 -1.38 👍
Working memory 9.46 🙂 9.54 🙂 0.08 👎
Quality 57.91% 🙂 57.96% 🙂 0.05% 👍
Other metrics Before After Change
Lines 565 560 -5
Changed files Quality Before Quality After Quality Change
server/code.py 76.80% ⭐ 79.08% ⭐ 2.28% 👍
server/insta.py 49.03% 😞 49.22% 😞 0.19% 👍
server_bottle/bottle_app.py 74.35% 🙂 77.18% ⭐ 2.83% 👍
server_bottle/insta.py 49.03% 😞 49.22% 😞 0.19% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
server/insta.py get_content 6 ⭐ 343 ⛔ 16 ⛔ 37.10% 😞 Try splitting into smaller methods. Extract out complex expressions
server_bottle/insta.py get_content 6 ⭐ 343 ⛔ 16 ⛔ 37.10% 😞 Try splitting into smaller methods. Extract out complex expressions
server/insta.py pretty_date 21 😞 167 😞 7 🙂 49.23% 😞 Refactor to reduce nesting. Try splitting into smaller methods
server_bottle/insta.py pretty_date 21 😞 167 😞 7 🙂 49.23% 😞 Refactor to reduce nesting. Try splitting into smaller methods
server/insta.py login 6 ⭐ 189 😞 9 🙂 55.39% 🙂 Try splitting into smaller methods

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants