From 95c7a65b916ec70583824b10ec7d2b5c64dc575c Mon Sep 17 00:00:00 2001 From: Kuai-sama <77694138+Kuai-sama@users.noreply.github.com> Date: Sun, 3 Apr 2022 12:33:24 +0200 Subject: [PATCH] V1.2 Fixed minor bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed a minor bug that was incorrectly incrementing the "N°" column --- TVTime.py | 162 +++++++++++++++++++++++++++--------------------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/TVTime.py b/TVTime.py index 84a566b..69490a3 100644 --- a/TVTime.py +++ b/TVTime.py @@ -1,81 +1,81 @@ -from tvtimewrapper import TVTimeWrapper -import pandas -import json -import os - -""" - Author : Kuaï - Github : Kuai-sama - Created date project : 18/02/2022 - Last update : 23/02/2022 - Current version : v1.1 - Python interpretor : 3.8.7 64 bit - - Goals of the Project : Exporting accurately data from TvTime to cvs file -""" - -dir_path = os.path.dirname(os.path.realpath( - __file__)) # Current directory project -file_name_json = dir_path + os.sep + r"data.json" -file_name_csv = dir_path + os.sep + r"dataTVTime.csv" - -# Connection -tvtime = TVTimeWrapper(r"YourUserName", r"YourPassword") -print("Connection to TVTimeWrapper module") - -# Get all the shows that the user have followed -ShowFollowed = tvtime.show.followed() - -list = ['1', '1,3', '1,5', '2', '2,6', '3', '4'] -# Keep only one image for all shows -for element in ShowFollowed: - del element["all_images"]["banner"] - del element["all_images"]["fanart"] - for i in list: - del element["all_images"]["poster"][i] - -print("Get selected data of all the shows that you have followed") - -# Send the modified data in to a real json file -with open(file_name_json, 'w') as my_file: - json.dump(ShowFollowed, my_file) - -# Convert json to csv data -pandas.read_json(file_name_json).to_csv(file_name_csv) - -# Read the file -data = pandas.read_csv(file_name_csv) - -# List of all columns to be deleted -columns_To_Be_Deleted = ['last_seen', 'last_aired', 'next_aired', 'followed', 'archived', 'diffusion', 'folder', - 'notification_type', 'is_web_serie', 'hashtag', 'number_of_seasons', 'favorite'] - -# Drop useless columns from the CSV data -for column in columns_To_Be_Deleted: - data.pop(column) - -# Remove shows already seen -index = data[data['up_to_date'] == True].index -data.drop(index, inplace=True) - -''' - By default, when converting json data to csv, it creates a column named "Unnamed: 0", which refers to the iteration number of your show. so wer rename the column to "N°" -''' -data.rename(columns={"Unnamed: 0": "N°"}, inplace=True) -data.columns - -# Remove {'poster': {'0': in all_images column -for key, value in data.iterrows(): - NewString = '{}'.format(value["all_images"]).lstrip("{'poster': {'0': '") - data.loc[key, "all_images"] = NewString[:-3] -# Increment the column "N°" - incremented_value = '{}'.format(value["N°"]) - incremented_value = int(incremented_value) - incremented_value += 1 - data.loc[key, "N°"] = incremented_value - -print(data) # display - -# Saving file -data.to_csv(file_name_csv, index=None) -print("Saved file") +# coding: utf-8 +from tvtimewrapper import TVTimeWrapper +import pandas +import json +import os + +""" + Author : Kuaï + Github : Kuai-sama + Created date project : 18/02/2022 + Last update : 03/04/2022 + Current version : v1.1 + Python interpretor : 3.8.7 64 bit + Goals of the Project : Exporting accurately data from TvTime to cvs file +""" + +dir_path = os.path.dirname(os.path.realpath( + __file__)) # Current directory project + +file_name_json = dir_path + os.sep + r"data.json" +file_name_csv = dir_path + os.sep + r"dataTVTime.csv" + +# Connection +tvtime = TVTimeWrapper(r"YourUserName", r"YourPassword") +print("Connection to TVTimeWrapper module") + +# Get all the shows that the user have followed +ShowFollowed = tvtime.show.followed() + +list = ['1', '1,3', '1,5', '2', '2,6', '3', '4'] +# Keep only one image for all shows +for element in ShowFollowed: + del element["all_images"]["banner"] + del element["all_images"]["fanart"] + for i in list: + del element["all_images"]["poster"][i] + +print("Get selected data of all the shows that you have followed") + +# Send the modified data in to a real json file +with open(file_name_json, 'w') as my_file: + json.dump(ShowFollowed, my_file) + +# Convert json to csv data +pandas.read_json(file_name_json).to_csv(file_name_csv) + +# Read the file +data = pandas.read_csv(file_name_csv) + +# List of all columns to be deleted +columns_To_Be_Deleted = ['last_seen', 'last_aired', 'next_aired', 'followed', 'archived', 'diffusion', 'folder', + 'notification_type', 'is_web_serie', 'hashtag', 'number_of_seasons', 'favorite'] + +# Drop useless columns from the CSV data +for column in columns_To_Be_Deleted: + data.pop(column) + +# Remove shows already seen +index = data[data['up_to_date'] == True].index +data.drop(index, inplace=True) + +''' + By default, when converting json data to csv, it creates a column named "Unnamed: 0", which refers to the iteration number of your show. so we have rename the column to "N°" +''' +data.rename(columns={"Unnamed: 0": "N°"}, inplace=True) +data.columns + +incremented_value = 0 +# Remove {'poster': {'0': in all_images column +for key, value in data.iterrows(): + NewString = '{}'.format(value["all_images"]).lstrip("{'poster': {'0': '") + data.loc[key, "all_images"] = NewString[:-3] +# Increment the column "N°" + incremented_value += 1 + data.loc[key, "N°"] = incremented_value + +print(data) # display + +# Saving file +data.to_csv(file_name_csv, index=None) +print("Saved file")