def main():
    for region in region_list:
        for i in range(len(week_list)):
            api = SpotifyCharts()
            file_name ='./data/' + region +'.csv'
            api.top200Daily(output_file = file_name, region = [region],
                            start = week_list[i], end = week_list[i])
示例#2
0
def main(chart, start, end, csv, region, webhook):
    """ CLI version of fycharts (https://pypi.org/project/fycharts/)
	
	fycharts [OPTIONS] chartName

	===== EXAMPLES

	fycharts --csv out.csv viral50Weekly
	
	fycharts --start 2020-05-06 --end 2020-10-10 --csv out.csv viral50Weekly
	
	fycharts --region US viral50Weekly
	
	fycharts -r US -r UK viral50Weekly
	
	fycharts --webhook https://mywebhook.site/1232/post viral50Weekly
	
	fycharts -w https://mywebhook.site/1/post -w https://mywebhook.site/2/post viral50Weekly
	
	======
	"""
    region = list(region)
    webhook = list(webhook)

    if (len(region) == 0):
        region = None

    if (len(webhook) == 0 and csv == ''):
        click.secho(
            "ERROR: Please set at least one output mode (CSV or webhooks)",
            fg="red",
            bold=True)
    else:
        api = SpotifyCharts()
        chart_choices = [
            "top200Weekly", "top200Daily", "viral50Weekly", "viral50Daily"
        ]

        if (chart == "top200Weekly"):
            click.secho("Extracting top200Weekly...", fg="cyan", bold=True)
            api.top200Weekly(csv, None, webhook, start, end, region)
            click.secho("Extraction complete\n", fg="white", bold=True)
        elif (chart == "top200Daily"):
            click.secho("Extracting top200Daily...", fg="cyan", bold=True)
            api.top200Daily(csv, None, webhook, start, end, region)
            click.secho("Extraction complete\n", fg="white", bold=True)
        elif (chart == "viral50Weekly"):
            click.secho("Extracting viral50Weekly...", fg="cyan", bold=True)
            api.viral50Weekly(csv, None, webhook, start, end, region)
            click.secho("Extraction complete\n", fg="white", bold=True)
        elif (chart == "viral50Daily"):
            click.secho("Extracting viral50Daily...", fg="cyan", bold=True)
            api.viral50Daily(csv, None, webhook, start, end, region)
            click.secho("Extraction complete\n", fg="white", bold=True)
        else:
            click.secho(
                f"ERROR: {chart} could not be processed. Select either of: {', '.join(chart_choices)}",
                fg="red",
                bold=True)
def main():
    api = SpotifyCharts()
    """database is created for future expansion tough technically not necessary for the project"""
    connector = sqlalchemy.create_engine("sqlite:///spotifycharts.db",
                                         echo=False)
    hooks = ["https://mywebhookssite.com/post/", "http://asecondsite.net/post"]

    #Select what you want to study by un-commenting and changing the file name the in "get_audio_features.py"
    #defult is set to top50 weekly
    #Don't forget to uncomment threads
    a_thread = threading.Thread(target=api.top200Daily,
                                kwargs={
                                    "output_file": "top_200_daily.csv",
                                    "output_db": connector,
                                    "webhook": hooks,
                                    "start": "2020-01-03",
                                    "end": "2020-01-12",
                                    "region": ["global", "us"]
                                })  #Change variables as needed
    b_thread = threading.Thread(target=api.top200Weekly,
                                kwargs={
                                    "output_file": "top_200_weekly.csv",
                                    "output_db": connector,
                                    "webhook": hooks,
                                    "start": "2020-01-03",
                                    "end": "2020-01-12",
                                    "region": ["global", "us"]
                                })
    c_thread = threading.Thread(target=api.viral50Daily,
                                kwargs={
                                    "output_file": "viral_50_daily.csv",
                                    "output_db": connector,
                                    "webhook": hooks,
                                    "start": "2020-01-03",
                                    "end": "2020-01-12",
                                    "region": ["global", "us"]
                                })
    d_thread = threading.Thread(target=api.viral50Weekly,
                                kwargs={
                                    "output_file": "viral_50_weekly.csv",
                                    "output_db": connector,
                                    "webhook": hooks,
                                    "start": "2020-01-02",
                                    "end": "2020-01-12",
                                    "region": ["global", "us"]
                                })

    #when in use uncomment these too
    a_thread.start()
    b_thread.start()
    c_thread.start()
    d_thread.start()
from fycharts.SpotifyCharts import SpotifyCharts

api = SpotifyCharts()
api.top200Daily(output_file="output.csv",
                start="2017-01-01",
                end="2021-01-19",
                region=[
                    "dk", "gr", "is", "ch", "it", "pl", "at", "tr", "ee", "lt",
                    "nl", "be", "es", "hu", "lu", "no", "ro", "bg", "fi", "lv",
                    "se", "cz", "fr", "ie", "de", "gb", "sk", "global"
                ])
示例#5
0
from fycharts.SpotifyCharts import SpotifyCharts

fyApi = SpotifyCharts()

fyApi.viral50Daily(output_file="viral_50_daily.csv",
                   start="2020-11-01",
                   end="2020-12-01",
                   region='us')
示例#6
0
from firebase import firebase
from datetime import datetime, timedelta
import csv
from fycharts.SpotifyCharts import SpotifyCharts
import time

# get date
date = datetime.now() - timedelta(10)
date = date.strftime('%Y-%m-%d')

# write chart to csv
api = SpotifyCharts()
api.top200Daily(output_file="temp.csv",
                start=date,
                end=date,
                region=["global"])
time.sleep(5)

# write to db from csv
fb = firebase.FirebaseApplication(
    'https://spotifychartsdatabase-default-rtdb.firebaseio.com/', None)
with open('temp.csv', encoding="utf8") as f:
    csv_reader = csv.reader(f, delimiter=',')
    for row in csv_reader:
        if len(row) > 0 and row[4] != 'date':
            data = {
                "position": row[0],
                "track name": row[1],
                "artist": row[2],
                "streams": row[3],
                "date": row[4],
示例#7
0
# coding : utf-8

from fycharts.SpotifyCharts import SpotifyCharts
api = SpotifyCharts()

api.top200Daily(output_file="top_200_daily.csv",
                start="2017-01-01",
                end="2017-02-22",
                region=["global"])
api.top200Daily(output_file="top_200_daily.csv",
                start="2017-02-24",
                end="2017-05-29",
                region=["global"])
api.top200Daily(output_file="top_200_daily.csv",
                start="2017-06-01",
                end="2017-06-01",
                region=["global"])
api.top200Daily(output_file="top_200_daily.csv",
                start="2017-06-03",
                end="2019-12-31",
                region=["global"])

print(api)