mirror of
https://github.com/Xevion/v1.xevion.dev.git
synced 2025-12-10 14:09:08 -06:00
PyCharm grand repo wide reformat
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import logging, sys, os, json
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Path to API Credentials file
|
||||
PATH = os.path.join(sys.path[0], 'auth.json')
|
||||
@@ -9,11 +12,11 @@ if not os.path.exists(PATH):
|
||||
# Dump a pretty-printed dictionary with default values
|
||||
json.dump(
|
||||
{
|
||||
'USERNAME' : 'Your Username Here',
|
||||
'CLIENT_ID' : 'Your Client ID Here',
|
||||
'CLIENT_SECRET' : 'Your Client Secret Here',
|
||||
'REDIRECT_URI' : 'Your Redirect URI Callback Here',
|
||||
'SCOPE' : ['Your Scopes Here']
|
||||
'USERNAME': 'Your Username Here',
|
||||
'CLIENT_ID': 'Your Client ID Here',
|
||||
'CLIENT_SECRET': 'Your Client Secret Here',
|
||||
'REDIRECT_URI': 'Your Redirect URI Callback Here',
|
||||
'SCOPE': ['Your Scopes Here']
|
||||
},
|
||||
file,
|
||||
indent=3
|
||||
@@ -31,4 +34,4 @@ USERNAME = FILE['USERNAME']
|
||||
CLIENT_ID = FILE['CLIENT_ID']
|
||||
CLIENT_SECRET = FILE['CLIENT_SECRET']
|
||||
REDIRECT_URI = FILE['REDIRECT_URI']
|
||||
SCOPE = ' '.join(FILE['SCOPE'])
|
||||
SCOPE = ' '.join(FILE['SCOPE'])
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
|
||||
from . import auth
|
||||
from . import pull
|
||||
from . import process
|
||||
import logging
|
||||
from . import pull
|
||||
|
||||
|
||||
def main():
|
||||
@@ -14,6 +15,7 @@ def main():
|
||||
refresh()
|
||||
process.main()
|
||||
|
||||
|
||||
# Refreshes tracks from files if the token from Spotipy has expired,
|
||||
# thus keeping us up to date in most cases while keeping rate limits
|
||||
def refresh():
|
||||
@@ -28,5 +30,6 @@ def refresh():
|
||||
else:
|
||||
pull.main()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import logging
|
||||
import datetime
|
||||
import collections
|
||||
import numpy as np
|
||||
import os
|
||||
|
||||
import dateutil.parser
|
||||
import PIL.Image as Image
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
|
||||
# Gets all files in tracks folder, returns them in parsed JSON
|
||||
def get_files():
|
||||
@@ -20,6 +18,7 @@ def get_files():
|
||||
)
|
||||
return files
|
||||
|
||||
|
||||
# Simple function to combine a bunch of items from different files
|
||||
def combine_files(files):
|
||||
items = []
|
||||
@@ -27,6 +26,7 @@ def combine_files(files):
|
||||
items.extend(file['items'])
|
||||
return items
|
||||
|
||||
|
||||
# Prints the data in a interesting format
|
||||
def print_data(data):
|
||||
for i, item in enumerate(data):
|
||||
@@ -36,6 +36,7 @@ def print_data(data):
|
||||
artists = ' & '.join(artist['name'] for artist in item['track']['artists'])
|
||||
print('[{}] {} "{}" by {}'.format(date, explicit, track_name, artists))
|
||||
|
||||
|
||||
def process_data(data):
|
||||
# Process the data by Month/Year, then by Clean/Explicit
|
||||
scores = {}
|
||||
@@ -44,7 +45,7 @@ def process_data(data):
|
||||
if date not in scores.keys():
|
||||
scores[date] = [0, 0]
|
||||
scores[date][1 if item['track']['explicit'] else 0] += 1
|
||||
|
||||
|
||||
# Create simplified arrays for each piece of data
|
||||
months = list(scores.keys())[::-1]
|
||||
clean, explicit = [], []
|
||||
@@ -59,17 +60,17 @@ def process_data(data):
|
||||
ind = np.arange(n)
|
||||
width = 0.55
|
||||
# Resizer figuresize to be 2.0 wider
|
||||
plt.figure(figsize=(10.0, 6.0))
|
||||
plt.figure(figsize=(10.0, 6.0))
|
||||
# Stacked Bars
|
||||
p1 = plt.bar(ind, explicit, width)
|
||||
p2 = plt.bar(ind, clean, width, bottom=explicit) # bottom= just has the bar sit on top of the explicit
|
||||
p2 = plt.bar(ind, clean, width, bottom=explicit) # bottom= just has the bar sit on top of the explicit
|
||||
# Plot labeling
|
||||
plt.title('Song Count by Clean/Explicit')
|
||||
plt.ylabel('Song Count')
|
||||
plt.xlabel('Month')
|
||||
plt.xticks(ind, months, rotation=270) # Rotation 90 will have the
|
||||
plt.xticks(ind, months, rotation=270) # Rotation 90 will have the
|
||||
plt.legend((p1[0], p2[0]), ('Explicit', 'Clean'))
|
||||
fig = plt.gcf() # Magic to save to image and then show
|
||||
fig = plt.gcf() # Magic to save to image and then show
|
||||
|
||||
# Save the figure, overwriting anything in your way
|
||||
logging.info('Saving the figure to the \'export\' folder')
|
||||
@@ -86,7 +87,7 @@ def process_data(data):
|
||||
dpi=100,
|
||||
quality=95
|
||||
)
|
||||
|
||||
|
||||
# Finally show the figure to
|
||||
logging.info('Showing plot to User')
|
||||
# plt.show()
|
||||
@@ -95,6 +96,7 @@ def process_data(data):
|
||||
# logging.info('Copying the plot data to clipboard')
|
||||
# copy(months, clean, explicit)
|
||||
|
||||
|
||||
# Simple method for exporting data to a table like format
|
||||
# Will paste into Excel very easily
|
||||
def copy(months, clean, explicit):
|
||||
@@ -104,6 +106,7 @@ def copy(months, clean, explicit):
|
||||
f'{item[0]}\t{item[1]}\t{item[2]}' for item in zip(months, clean, explicit)
|
||||
]))
|
||||
|
||||
|
||||
def main():
|
||||
# logging.basicConfig(level=logging.INFO)
|
||||
logging.info("Reading track files")
|
||||
@@ -111,7 +114,7 @@ def main():
|
||||
logging.info(f"Read and parse {len(files)} track files")
|
||||
logging.info("Combining into single track file for ease of access")
|
||||
data = combine_files(files)
|
||||
data.sort(key=lambda item : dateutil.parser.parse(item['added_at']).timestamp(), reverse=True)
|
||||
data.sort(key=lambda item: dateutil.parser.parse(item['added_at']).timestamp(), reverse=True)
|
||||
logging.info(f'File combined with {len(data)} items')
|
||||
logging.info('Processing file...')
|
||||
process_data(data)
|
||||
process_data(data)
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import os
|
||||
import sys
|
||||
from . import auth
|
||||
import json
|
||||
import shutil
|
||||
import pprint
|
||||
import spotipy
|
||||
import logging
|
||||
from hurry.filesize import size, alternative
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from hurry.filesize import size, alternative
|
||||
|
||||
from . import auth
|
||||
|
||||
|
||||
def main():
|
||||
# Get Authorization
|
||||
@@ -27,8 +28,8 @@ def main():
|
||||
tracks_folder = os.path.join(os.path.dirname(__file__), 'tracks')
|
||||
logging.warning('Clearing all files in tracks folder for new files')
|
||||
if os.path.exists(tracks_folder):
|
||||
shutil.rmtree(tracks_folder) # Delete folder and all contents (old track files)
|
||||
os.makedirs(tracks_folder) # Recreate the folder just deleted
|
||||
shutil.rmtree(tracks_folder) # Delete folder and all contents (old track files)
|
||||
os.makedirs(tracks_folder) # Recreate the folder just deleted
|
||||
logging.info('Cleared folder, ready to download new track files')
|
||||
|
||||
curoffset, curlimit = 0, 50
|
||||
@@ -62,4 +63,4 @@ def main():
|
||||
))
|
||||
break
|
||||
# Continuing, so increment offset
|
||||
curoffset += curlimit
|
||||
curoffset += curlimit
|
||||
|
||||
Reference in New Issue
Block a user