Fix minor code style issues

This makes instaloder proof against
$ pylint3 -r n -d \
	bad-whitespace,bad-continuation,missing-docstring,anomalous-backslash-in-string,invalid-name,multiple-imports,dangerous-default-value \
	--max-args=8 --max-locals=16 --max-branches=19 --max-nested-blocks=6 \
	instagram
This commit is contained in:
Alexander Graf 2016-06-26 09:43:02 +02:00
parent b3b8c22240
commit beb860ed35

View File

@ -1,16 +1,18 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import requests, re, json, datetime, shutil, os, time, random, sys, pickle, getpass import re, json, datetime, shutil, os, time, random, sys, pickle, getpass
from io import BytesIO from io import BytesIO
from argparse import ArgumentParser
import requests
class DownloaderException(Exception): class DownloaderException(Exception):
pass pass
def get_json(name, id = 0, session=None, SleepMinMax=[1,5]): def get_json(name, max_id = 0, session=None, SleepMinMax=[1,5]):
if session is None: if session is None:
session = get_session(None, None, True) session = get_session(None, None, True)
r = session.get('http://www.instagram.com/'+name, \ r = session.get('http://www.instagram.com/'+name, \
params={'max_id': id}) params={'max_id': max_id})
time.sleep(abs(SleepMinMax[1]-SleepMinMax[0])*random.random()+SleepMinMax[0]) time.sleep(abs(SleepMinMax[1]-SleepMinMax[0])*random.random()+SleepMinMax[0])
m = re.search('window\._sharedData = .*<', r.text) m = re.search('window\._sharedData = .*<', r.text)
if m is None: if m is None:
@ -72,7 +74,7 @@ def saveCaption(name, date_epoch, caption):
while os.path.isfile(get_filename(i)): while os.path.isfile(get_filename(i)):
i = i + 1 i = i + 1
for index in range(i, 0, -1): for index in range(i, 0, -1):
os.rename(get_filename(index-1), get_filename(index)); os.rename(get_filename(index-1), get_filename(index))
print('txt updated', end=' ', flush=True) print('txt updated', end=' ', flush=True)
print('txt', end=' ', flush=True) print('txt', end=' ', flush=True)
os.makedirs(name.lower(), exist_ok=True) os.makedirs(name.lower(), exist_ok=True)
@ -126,10 +128,7 @@ def test_login(user, session):
return False return False
r = session.get('https://www.instagram.com/') r = session.get('https://www.instagram.com/')
time.sleep(4 * random.random() + 1) time.sleep(4 * random.random() + 1)
if r.text.find(user.lower()) != -1: return r.text.find(user.lower()) != -1
return True
else:
return False
def get_session(user, passwd, EmptySessionOnly=False, session=None): def get_session(user, passwd, EmptySessionOnly=False, session=None):
def instaheader(): def instaheader():
@ -232,7 +231,6 @@ def download(name, username = None, password = None, sessionfile = None, \
save_object(session, sessionfile) save_object(session, sessionfile)
if __name__ == "__main__": if __name__ == "__main__":
from argparse import ArgumentParser
parser = ArgumentParser(description='Simple downloader to fetch all Instagram pics and '\ parser = ArgumentParser(description='Simple downloader to fetch all Instagram pics and '\
'captions from a given profile') 'captions from a given profile')
parser.add_argument('target', help='Name of profile to download') parser.add_argument('target', help='Name of profile to download')