Print message when session is loaded or saved
This commit is contained in:
parent
37a316583a
commit
6583388abf
16
instagram.py
16
instagram.py
@ -125,22 +125,22 @@ def download_profilepic(name, url, quiet=False):
|
|||||||
else:
|
else:
|
||||||
raise DownloaderException("file \'" + url + "\' could not be downloaded")
|
raise DownloaderException("file \'" + url + "\' could not be downloaded")
|
||||||
|
|
||||||
def save_object(obj, filename):
|
def save_object(obj, filename, quiet=False):
|
||||||
if filename is None:
|
if filename is None:
|
||||||
filename = DEFAULTSESSIONFILE
|
filename = DEFAULTSESSIONFILE
|
||||||
with open(filename, 'wb') as file:
|
with open(filename, 'wb') as file:
|
||||||
|
log("Saved session to %s." % filename, quiet=quiet)
|
||||||
os.chmod(filename, 0o600)
|
os.chmod(filename, 0o600)
|
||||||
shutil.copyfileobj(BytesIO(pickle.dumps(obj, -1)), file)
|
shutil.copyfileobj(BytesIO(pickle.dumps(obj, -1)), file)
|
||||||
|
|
||||||
def load_object(filename):
|
def load_object(filename, quiet=False):
|
||||||
if filename is None:
|
if filename is None:
|
||||||
filename = DEFAULTSESSIONFILE
|
filename = DEFAULTSESSIONFILE
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
with open(filename, 'rb') as sessionfile:
|
with open(filename, 'rb') as sessionfile:
|
||||||
obj = pickle.load(sessionfile)
|
obj = pickle.load(sessionfile)
|
||||||
return obj
|
log("Loaded session from %s." % filename, quiet=quiet)
|
||||||
else:
|
return obj
|
||||||
return None
|
|
||||||
|
|
||||||
def test_login(user, session):
|
def test_login(user, session):
|
||||||
if user is None or session is None:
|
if user is None or session is None:
|
||||||
@ -201,7 +201,7 @@ def download(name, username = None, password = None, sessionfile = None, \
|
|||||||
# pylint:disable=too-many-arguments,too-many-locals,too-many-nested-blocks,too-many-branches
|
# pylint:disable=too-many-arguments,too-many-locals,too-many-nested-blocks,too-many-branches
|
||||||
# We are aware that this function has many arguments, many local variables, many nested blocks
|
# We are aware that this function has many arguments, many local variables, many nested blocks
|
||||||
# and many branches. But we don't care.
|
# and many branches. But we don't care.
|
||||||
session = load_object(sessionfile)
|
session = load_object(sessionfile, quiet=quiet)
|
||||||
data = get_json(name, session=session)
|
data = get_json(name, session=session)
|
||||||
if len(data["entry_data"]) == 0 or "ProfilePage" not in data["entry_data"]:
|
if len(data["entry_data"]) == 0 or "ProfilePage" not in data["entry_data"]:
|
||||||
raise ProfileNotExistsException("user %s does not exist" % name)
|
raise ProfileNotExistsException("user %s does not exist" % name)
|
||||||
@ -256,12 +256,12 @@ def download(name, username = None, password = None, sessionfile = None, \
|
|||||||
log(quiet=quiet)
|
log(quiet=quiet)
|
||||||
if fast_update and not downloaded:
|
if fast_update and not downloaded:
|
||||||
if test_login(username, session):
|
if test_login(username, session):
|
||||||
save_object(session, sessionfile)
|
save_object(session, sessionfile, quiet=quiet)
|
||||||
return username
|
return username
|
||||||
data = get_json(name, get_last_id(data), session)
|
data = get_json(name, get_last_id(data), session)
|
||||||
time.sleep(abs(sleep_min_max[1]-sleep_min_max[0])*random.random()+abs(sleep_min_max[0]))
|
time.sleep(abs(sleep_min_max[1]-sleep_min_max[0])*random.random()+abs(sleep_min_max[0]))
|
||||||
if test_login(username, session):
|
if test_login(username, session):
|
||||||
save_object(session, sessionfile)
|
save_object(session, sessionfile, quiet=quiet)
|
||||||
return username
|
return username
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
Loading…
Reference in New Issue
Block a user