Skip to content
This repository has been archived by the owner on Apr 24, 2021. It is now read-only.

Commit

Permalink
🎨 Imporoving code structure (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefin authored Jul 19, 2020
1 parent f40eadb commit fe868d3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
72 changes: 38 additions & 34 deletions instadown/ig.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,44 @@ def get_link_by_end(after, idd, query_hash):
'Upgrade-Insecure-Requests': '1',
}

try:
username = sys.argv[1]
query_hash = sys.argv[2]
def main():
try:
os.mkdir('POSTS/')
except:
pass
try:
os.mkdir('POSTS/' + username + '/')
except:
pass
url = "https://www.instagram.com/" + username
user_doc = requests.get(url, headers=headers).text
json_data = re.search('window._sharedData = (.*);</script>', user_doc).group(1)
d = json.loads(json_data)
account_id = str(d['entry_data']['ProfilePage'][0]['graphql']['user']['id'])
end_cursor = str(
d['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['page_info']['end_cursor'])
uid = d['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'][0]['node'][
'shortcode']
sency, endlink = get_link_by_end(get_end_cursor(uid), account_id, query_hash)
while True:
for k in sency:
username = sys.argv[1]
query_hash = sys.argv[2]
try:
os.mkdir('POSTS/')
except:
pass
try:
os.mkdir('POSTS/' + username + '/')
except:
pass
url = "https://www.instagram.com/" + username
user_doc = requests.get(url, headers=headers).text
json_data = re.search('window._sharedData = (.*);</script>', user_doc).group(1)
d = json.loads(json_data)
account_id = str(d['entry_data']['ProfilePage'][0]['graphql']['user']['id'])
end_cursor = str(
d['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['page_info']['end_cursor'])
uid = d['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges'][0]['node'][
'shortcode']
sency, endlink = get_link_by_end(get_end_cursor(uid), account_id, query_hash)
while True:
for k in sency:
try:
download_content(k, username)
except requests.exceptions.ReadTimeout:
logging.info("Download Failed!!")
try:
download_content(k, username)
sency, endlink = get_link_by_end(endlink, account_id, query_hash)
except requests.exceptions.ReadTimeout:
logging.info("Download Failed!!")
try:
sency, endlink = get_link_by_end(endlink, account_id, query_hash)
except requests.exceptions.ReadTimeout:
logging.info("End link fetching failed!!")
except requests.exceptions.ReadTimeout:
logging.info("\n\n" + str(image_counter) + " Images Downloaded!!")
logging.info(str(video_counter) + " Videos Downloaded!!")
except KeyboardInterrupt:
logging.info("\n\n" + str(image_counter) + " Images Downloaded!!")
logging.info(str(video_counter) + " Videos Downloaded!!")
logging.info("End link fetching failed!!")
except requests.exceptions.ReadTimeout:
logging.info("\n\n" + str(image_counter) + " Images Downloaded!!")
logging.info(str(video_counter) + " Videos Downloaded!!")
except KeyboardInterrupt:
logging.info("\n\n" + str(image_counter) + " Images Downloaded!!")
logging.info(str(video_counter) + " Videos Downloaded!!")

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
EMAIL = 'sstefin@bk.ru'
AUTHOR = 'Stef'
REQUIRES_PYTHON = '>=3.6.0'
VERSION = '0.1.2'
VERSION = '0.1.6'

# What packages are required for this module to be executed?
REQUIRED = [
Expand Down

0 comments on commit fe868d3

Please # to comment.