MCPcopy
hub / github.com/InstaPy/InstaPy / store_active_unfollowers

Function store_active_unfollowers

instapy/relationship_tools.py:1044–1077  ·  view source on GitHub ↗

Store active Unfollowers data in a local storage at generated date

(username, active_unfollowers, logger, logfolder)

Source from the content-addressed store, hash-verified

1042
1043
1044def store_active_unfollowers(username, active_unfollowers, logger, logfolder):
1045 """Store active Unfollowers data in a local storage at generated date"""
1046 generation_date = datetime.today().strftime("%d-%m-%Y")
1047 active_unfollowers_size = len(active_unfollowers)
1048 file_directory = (
1049 "{}/relationship_data/{}"
1050 "/unfollowers/active_unfollowers/".format(logfolder, username)
1051 )
1052 file_name = "{}{}~active~{}".format(
1053 file_directory, generation_date, active_unfollowers_size
1054 )
1055 file_index = 0
1056 final_file = "{}.json".format(file_name)
1057
1058 try:
1059 if not os.path.exists(file_directory):
1060 os.makedirs(file_directory)
1061 # this loop provides unique data files
1062 while os.path.isfile(final_file):
1063 file_index += 1
1064 final_file = "{}({}).json".format(file_name, file_index)
1065
1066 with open(final_file, "w") as active_unfollowers_data:
1067 with interruption_handler():
1068 json.dump(active_unfollowers, active_unfollowers_data)
1069 logger.info(
1070 "Stored active Unfollowers data at {} local file\n".format(final_file)
1071 )
1072
1073 except Exception as exc:
1074 logger.info(
1075 "Failed to store active Unfollowers data in a local file :Z\n{}"
1076 "\n".format(str(exc).encode("utf-8"))
1077 )
1078
1079
1080def store_nonfollowers(

Callers 1

get_unfollowersFunction · 0.85

Calls 1

interruption_handlerFunction · 0.85

Tested by

no test coverage detected