-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathac_player_cl.py
executable file
·69 lines (55 loc) · 2.21 KB
/
ac_player_cl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python
# Play the Animal Crossing: New Leaf soundtrack in your command
# line according to the date, weather, and time of day!
import argparse
import datetime
import os
import requests
import subprocess
import time
# Add your OpenWeatherMap API key here!
WEATHER_URL = 'http://api.openweathermap.org/data/2.5/weather?q=NewYork&APPID='
WEATHER_API_KEY = ''
class AcPlayer:
def __init__(self):
self.song = ''
self.time = None
self.weather = ''
# Paths for songs depending on weather
self.clear_path = os.getcwd() + '/assets/songs/time/clear/'
self.rainy_path = os.getcwd() + '/assets/songs/time/rainy/'
self.snowy_path = os.getcwd() + '/assets/songs/time/snowy/'
self.get_weather()
def display_info(self):
print('It is currently {} o\'clock and {}.'.format(self.time, self.weather))
def get_weather(self):
response = requests.get(WEATHER_URL + WEATHER_API_KEY).json()
self.weather = response['weather'][0]['main']
def play(self):
playing = subprocess.call(['mplayer', self.song, '/dev/null'], stdout=subprocess.PIPE)
def update(self):
time = datetime.datetime.now().hour
if time != self.time:
self.time = time
if self.weather == 'Rain':
self.song = self.rainy_path + str(self.time) + '.mp3'
elif self.weather == 'Snow':
self.song = self.snowy_path + str(self.time) + '.mp3'
else:
self.song = self.clear_path + str(self.time) + '.mp3'
self.display_info()
def main():
parser = argparse.ArgumentParser(description='Play the Animal Crossing: New Leaf soundtrack according to time & weather',
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-a', '--api', choices=[0,1], default=None, type=str, help='OpenWeatherMap API key')
if WEATHER_API_KEY == '':
print('AC PLAYER: You must add an OpenWeatherMap API key before starting.')
exit(1)
print('ANIMAL CROSSING: NEW LEAF PLAYER')
print( '****** command line edition!')
player = AcPlayer()
while 1:
player.update()
player.play()
if __name__ == '__main__':
main()