mirror of
https://github.com/Xevion/spotify-explicit.git
synced 2025-12-06 05:16:36 -06:00
rework plot figure size to properly space labels
This commit is contained in:
3
main.py
3
main.py
@@ -25,5 +25,6 @@ def refresh():
|
||||
pull.main()
|
||||
else:
|
||||
logging.info('Spotify data deemed to be recent enough (under {} seconds old)'.format(cache['expires_in']))
|
||||
pull.main()
|
||||
else:
|
||||
pull.main()
|
||||
main()
|
||||
19
process.py
19
process.py
@@ -58,11 +58,13 @@ def process_data(data):
|
||||
n = len(scores.values())
|
||||
ind = np.arange(n)
|
||||
width = 0.55
|
||||
# Bars
|
||||
# Resizer figuresize to be 2.0 wider
|
||||
plt.figure(figsize=(10.0, 6.0))
|
||||
# Stacked Bars
|
||||
p1 = plt.bar(ind, explicit, width)
|
||||
p2 = plt.bar(ind, safe, width, bottom=explicit) # bottom= just has the bar sit on top of the explicit
|
||||
# Plot labeling
|
||||
plt.title('Song by Safe/Explicit')
|
||||
plt.title('Song Count by Safe/Explicit')
|
||||
plt.ylabel('Song Count')
|
||||
plt.xlabel('Month')
|
||||
plt.xticks(ind, months, rotation=270) # Rotation 90 will have the
|
||||
@@ -74,8 +76,15 @@ def process_data(data):
|
||||
export_folder = os.path.join(sys.path[0], 'export')
|
||||
if not os.path.exists(export_folder):
|
||||
os.makedirs(export_folder)
|
||||
plt.draw()
|
||||
fig.savefig(os.path.join(export_folder, datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S')))
|
||||
plt.tight_layout()
|
||||
fig.savefig(
|
||||
os.path.join(
|
||||
export_folder,
|
||||
datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S')
|
||||
),
|
||||
dpi=100,
|
||||
quality=95
|
||||
)
|
||||
|
||||
# Finally show the figure to
|
||||
logging.info('Showing plot to User')
|
||||
@@ -105,3 +114,5 @@ def main():
|
||||
logging.info(f'File combined with {len(data)} items')
|
||||
logging.info('Processing file...')
|
||||
process_data(data)
|
||||
|
||||
main()
|
||||
28
pull.py
28
pull.py
@@ -6,6 +6,7 @@ import shutil
|
||||
import pprint
|
||||
import spotipy
|
||||
import logging
|
||||
from hurry.filesize import size, alternative
|
||||
import spotipy.util as util
|
||||
|
||||
def main():
|
||||
@@ -27,21 +28,38 @@ def main():
|
||||
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.path.makedirs(tracks_folder) # Recreate the folder just deleted
|
||||
os.makedirs(tracks_folder) # Recreate the folder just deleted
|
||||
logging.info('Cleared folder, ready to download new track files')
|
||||
|
||||
curoffset, curlimit = 0, 50
|
||||
while curoffset >= 0:
|
||||
logging.info('Requesting tracks {} to {}'.format(curoffset, curoffset + curlimit))
|
||||
# Request and identify what was received
|
||||
logging.info('Requesting {} to {}'.format(curoffset, curoffset + curlimit))
|
||||
response = sp.current_user_saved_tracks(limit=curlimit, offset=curoffset)
|
||||
received = len(response['items'])
|
||||
logging.info('Received tracks {} to {}'.format(curoffset, curoffset + received))
|
||||
logging.info('Received {} to {}'.format(curoffset, curoffset + received))
|
||||
# Create path/filename
|
||||
filename = f'saved-tracks-{curoffset}-{curoffset + received}.json'
|
||||
filepath = os.path.join(tracks_folder, filename)
|
||||
# Save track file
|
||||
with open(filepath, 'w+') as file:
|
||||
json.dump(response, file)
|
||||
logging.info('Saved at "{}" ({}KB)'.format(f'\\tracks\\{filename}', round(os.path.getsize(filepath) / 1024, 2)))
|
||||
logging.info('Saved at "{}" ({})'.format(
|
||||
f'\\tracks\\{filename}',
|
||||
size(os.path.getsize(filepath)))
|
||||
)
|
||||
# Decide whether we have received all possible tracks
|
||||
if received < curlimit:
|
||||
logging.info('Done requesting/saving tracks after {} tracks'.format(curoffset + received))
|
||||
logging.info('Requested and saved {} tracks split over {} files ({})'.format(
|
||||
curoffset + received,
|
||||
len(os.listdir(tracks_folder)),
|
||||
size(
|
||||
sum(
|
||||
os.path.getsize(os.path.join(tracks_folder, file)) for file in os.listdir(tracks_folder)
|
||||
),
|
||||
system=alternative
|
||||
)
|
||||
))
|
||||
break
|
||||
# Continuing, so increment offset
|
||||
curoffset += curlimit
|
||||
Reference in New Issue
Block a user