MCPcopy
hub / github.com/InstaPy/InstaPy / update_activity

Function update_activity

instapy/util.py:535–639  ·  view source on GitHub ↗

1. Record every Instagram server call (page load, content load, likes, comments, follows, unfollow) 2. Take rotative screenshots 3. update connection state and record to .json file

(
    browser=None, action="server_calls", state=None, logfolder=None, logger=None
)

Source from the content-addressed store, hash-verified

533
534
535def update_activity(
536 browser=None, action="server_calls", state=None, logfolder=None, logger=None
537):
538 """
539 1. Record every Instagram server call (page load, content load, likes,
540 comments, follows, unfollow)
541 2. Take rotative screenshots
542 3. update connection state and record to .json file
543 """
544 # check action availability
545 quota_supervisor("server_calls")
546
547 # take screen shot
548 if browser and logfolder and logger:
549 take_rotative_screenshot(browser, logfolder)
550
551 # update state to JSON file
552 if state and logfolder and logger:
553 try:
554 path = "{}state.json".format(logfolder)
555 data = {}
556 # check if file exists and has content
557 if os.path.isfile(path) and os.path.getsize(path) > 0:
558 # load JSON file
559 with open(path, "r") as json_file:
560 data = json.load(json_file)
561
562 # update connection state
563 connection_data = {}
564 connection_data["connection"] = state
565 data["state"] = connection_data
566
567 # write to JSON file
568 with open(path, "w") as json_file:
569 json.dump(data, json_file, indent=4)
570 except Exception:
571 logger.warning("Unable to update JSON state file")
572
573 # in case is just a state update and there is no server call
574 if action is None:
575 return
576
577 # get a DB, start a connection and sum a server call
578 db, id = get_database()
579 conn = sqlite3.connect(db)
580
581 with conn:
582 conn.row_factory = sqlite3.Row
583 cur = conn.cursor()
584 # collect today data
585 cur.execute(
586 "SELECT * FROM recordActivity WHERE profile_id=:var AND "
587 "STRFTIME('%Y-%m-%d %H', created) == STRFTIME('%Y-%m-%d "
588 "%H', 'now', 'localtime')",
589 {"var": id},
590 )
591 data = cur.fetchone()
592

Callers 15

follow_userFunction · 0.85
get_given_user_followersFunction · 0.85
get_given_user_followingFunction · 0.85
unfollow_userFunction · 0.85
comment_imageFunction · 0.85
bypass_suspicious_loginFunction · 0.85
check_browserFunction · 0.85
login_userFunction · 0.85
dismiss_this_was_meFunction · 0.85
validate_usernameFunction · 0.85
get_active_usersFunction · 0.85

Calls 3

quota_supervisorFunction · 0.90
take_rotative_screenshotFunction · 0.85
get_databaseFunction · 0.85

Tested by

no test coverage detected