generated from heymynameiskai/template-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
78 lines (53 loc) · 2.58 KB
/
main.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
70
71
72
73
74
75
76
77
78
import api
import pdf
import plot
# import pprint
# pp = pprint.PrettyPrinter(indent=4)
def tablePrintHits(playlist_id): # THIS DOES NOT GENERATE PFDS, BUT PRINT DATA IN TERMINAL OUTPUT
# 1st: get basic attributes of playlist, like name
playlist_attributes_status = api.get_single_playlist(playlist_id)['status']
playlist_attributes = api.get_single_playlist(playlist_id)['content']
# check if API call worked
if playlist_attributes_status == 200:
playlist_name = playlist_attributes['name']
playlist_url = "https://cast.itunes.uni-muenchen.de/vod/playlists/" + playlist_id + ".html"
print("\n")
print(playlist_name)
print(playlist_url)
print("\n")
else:
print(
"Error while fetching API. Calling api.getPlaylistAttributes(" + playlist_id + ") returned HTTP-Status-Code: " + playlist_attributes_status)
# 2nd: get number of hits for each video in playlist
playlist_hits_status = api.get_playlist_total_hits(playlist_id)['status']
playlist_hits = api.get_playlist_total_hits(playlist_id)['content']
# check if API call worked
if playlist_hits_status == 200:
print("Video \t\t\t\t\t\t| Online \t| High Quality Video \t| Audio")
# print hits for each video
for i in sorted(playlist_hits.keys(), reverse=True):
print(playlist_hits[i]['name'] + "\t\t" + str(playlist_hits[i]['hits_online']) + "\t\t" + str(
playlist_hits[i]['hits_video']) + "\t\t\t" + str(playlist_hits[i]['hits_audio']))
print("\n")
else:
print(
"Error while fetching API. Calling api.getStatisticsByPlaylist(" + playlist_id + ") returned HTTP-Status-Code: " + playlist_attributes_status)
def printAllStatistics():
playlists = api.get_all_playlists()['content']
for i in playlists:
tablePrintHits(playlists[i]['id'])
def printPDF(playlist_id):
print("Trying to export " + playlist_id + "...")
playlist_attributes = api.get_single_playlist(playlist_id)
playlist_name = playlist_attributes['name']
playlist_url = playlist_attributes['url']
playlist_hits = api.get_playlist_total_hits(playlist_id)
pdf.printStatistics(file_name=playlist_name, date='heute', playlist_title=playlist_name, playlist_url=playlist_url, hits=playlist_hits)
def printAllPDF():
playlists = api.get_all_playlists()
print("Going to export " + str(len(playlists)) + " PDFs...")
for i in playlists:
printPDF(i['id'])
# printAllPDF()
# printPDF("JsSFM23oqr")
# plot.plot('hNYTXTtFGq', api.get_playlist_total_hits('hNYTXTtFGq'))