Store active Unfollowers data in a local storage at generated date
(username, active_unfollowers, logger, logfolder)
| 1042 | |
| 1043 | |
| 1044 | def 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 | |
| 1080 | def store_nonfollowers( |
no test coverage detected