-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Burkay/create data population scripts (#610)
* Added a script to fetch random account details and register them * Implemented a script to populate save_now_playing * Added requirements.txt
- Loading branch information
1 parent
ed3d383
commit a11f436
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import requests | ||
import pandas as pd | ||
import random | ||
import json | ||
|
||
|
||
def get_user_details(user_num=0): | ||
user_details = pd.read_csv("user_details.csv") | ||
user_details = user_details.iloc[user_num] | ||
user_details = user_details.to_dict() | ||
return user_details | ||
|
||
|
||
def get_song_links(path="songs.json"): | ||
with open(path) as f: | ||
songs = json.load(f) | ||
|
||
song_links = [] | ||
|
||
for track in songs["tracks"]["items"]: | ||
song_links.append(track["track"]["href"]) | ||
# track['link'] = f"https://open.spotify.com/track/{track['id']}" | ||
|
||
return song_links | ||
|
||
|
||
def save_now_playing_main(): | ||
world_cities = pd.read_csv("worldcities.csv") | ||
user_details_df = pd.read_csv("user_details.csv") | ||
# print(user_details) | ||
song_links = get_song_links() | ||
|
||
for user_idx in range(len(user_details_df)): | ||
user_details = user_details_df.iloc[user_idx].to_dict() | ||
city = world_cities.iloc[user_idx%len(world_cities)].to_dict() | ||
user_login_body = { | ||
"username": user_details["username"], | ||
"password": user_details["password"] | ||
} | ||
|
||
res = requests.post("https://spotonapp.win/api/login/", json=user_details, verify=False) | ||
print(res) | ||
|
||
song_link = song_links[user_idx%len(song_links)] | ||
|
||
now_playing_body = { | ||
"latitude": city["lat"], | ||
"longitude": city["lng"], | ||
"link": song_link | ||
} | ||
|
||
res = requests.post("https://spotonapp.win/api/save-now-playing/?", json=now_playing_body, verify=False) | ||
print(res) | ||
|
||
|
||
save_now_playing_main('songs.json') # This should be a path to a json file from a playlist spotify API call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import requests | ||
import pandas as pd | ||
import random | ||
|
||
def get_random_user_details(user_count=1): | ||
|
||
res = requests.get("https://randomuser.me/api/?results=" + str(user_count)+"&nat=de,dk,fr,gb,mx,nl,rs,tr,us") | ||
data = res.json() | ||
user_details = [] | ||
|
||
for user in data['results']: | ||
user_details.append({ | ||
"username": user['login']['username'], | ||
"name": user['name']['first'], | ||
"surname": user['name']['last'], | ||
"email": user['email'], | ||
"password": user['login']['password'], | ||
"labels": list(dict.fromkeys(random.choices(["Artist", "Listener","Teacher", "Producer"], k=2))) | ||
}) | ||
|
||
|
||
return user_details | ||
|
||
def register_accounts(user_count=1): | ||
|
||
url = "https://spotonapp.win/api/register/?" | ||
|
||
user_details = get_random_user_details(user_count) | ||
df = pd.DataFrame(user_details) | ||
df.to_csv("user_details.csv", index=False) | ||
|
||
for user in user_details: | ||
res = requests.post(url, json=user, verify=False) | ||
|
||
register_accounts(100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
attrs==24.3.0 | ||
beautifulsoup4==4.12.3 | ||
bs4==0.0.2 | ||
certifi==2024.12.14 | ||
charset-normalizer==3.4.0 | ||
fuzzysearch==0.7.2 | ||
idna==3.10 | ||
numpy==2.2.0 | ||
pandas==2.2.3 | ||
python-dateutil==2.9.0.post0 | ||
pytz==2024.2 | ||
requests==2.32.3 | ||
six==1.17.0 | ||
soupsieve==2.6 | ||
tzdata==2024.2 | ||
urllib3==2.2.3 |