import os import sqlite3 import requests def read_music_database(url): conn = sqlite3.connect(requests.get(url).content) c = conn.cursor() c.execute('SELECT * FROM music') music_list = c.fetchall() conn.close() return music_list def read_count_database(): conn = sqlite3.connect('assets/localwrapped/count.db') c = conn.cursor() c.execute('SELECT * FROM count') count_list = c.fetchall() conn.close() return count_list def total_play_time(url): total_time = 0 for countvar in read_count_database(): for musicvar in read_music_database(url): if countvar[0] == musicvar[0]: total_time += float(musicvar[-1]) * countvar[1] return total_time def generatehtmlcode(url): html = '\n\n' html += '\n\n\n\n' html += '\n\n' html += 'Halhadus\' Local Wrapped\n\n' html += '\n\n' html += '\n\n' html += '\n' html += '

Halhadus\' Local Wrapped

\n' html += '

Total Play Time: ' + str(int(total_play_time(url)/60)) + ' minutes

\n' html += '

Last Updated: ' + os.path.getmtime('assets/localwrapped/count.db') + '

\n' html += '

Most Played Musics

\n' html += '
    \n' count_list_formatted = [] for music in read_count_database(): music_name = music[0] count = music[1] count_list_formatted.append([music_name, count]) count_list_formatted.sort(key=lambda x: x[1], reverse=True) for music in count_list_formatted: html += '
  1. ' + music[0] + ' | ' + str(music[1]) + ' times
  2. \n' html += '
\n' html += '\n' return html