-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTiCrawler.py
144 lines (116 loc) · 4.55 KB
/
TiCrawler.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import argparse
from support_module import TcrawlTech
def main():
parser = argparse.ArgumentParser(
prog="TiCrawler - Vagalume Crawler",
usage="""python TikalCrawler.py [-a/--as_argument 'ARTIST']
[-p/-band_file_path 'FILE_PATH']
[-n/--number "NUMBER OF TOP SONGS" Max=25, Default_value=25]
[-as/-all_songs <This argument will bring all musics related to the artist>]
[-h/--help <This argument will bring up this menu>]
Exemplas of usage:
-Get n top songs:
python TiCrawler.py -a "Metallica" -n 3
output: '1) Nothing Else Matters
2) Enter Sandman
3) The Unforgiven'
python TiCrawler.py -p 'C://Bands.txt' -n 1
where: Bands.txt contains:
'Iron Maiden
Metallica
Elton John'
output: '1)Fear of The Dark
1)Nothing Else Matters
1)Your Song'
-Get all songs related to artist:
python TiCrawler.py -a "Metallica" -as
python TiCrawler.py -p 'C://Bands.txt' -as""",
description="A python script to search and show songs from a related artist",
)
parser.add_argument(
"artist",
type=str,
help='"Artist" or path of .txt file containing artist to be searched',
)
groupInput = parser.add_mutually_exclusive_group()
groupInput.add_argument(
"-p",
"--band_file_path",
action="store_true",
default=False,
help="To set the name of the artist from a .txt in the local path",
)
groupInput.add_argument(
"-a",
"--as_argument",
action="store_true",
default=False,
help="To set the name of the artist as a argument",
)
groupChoice = parser.add_mutually_exclusive_group()
groupChoice.add_argument(
"-n",
"--number",
type=int,
default=25,
help="Number of top songs to be extracted, 25 beeing the max",
)
groupChoice.add_argument(
"-as",
"--all_songs",
action="store_true",
default=False,
help="Extract all songs from your selected artist",
)
args = parser.parse_args()
if args.band_file_path:
# read all the lines from the band_file_path in case theres more than one band
band_file_path = open(args.artist, "r")
lines_list = band_file_path.readlines()
band_file_path.close()
for i in range(0, len(lines_list)):
lines_list[i] = str(lines_list[i].replace("\n", ""))
for j in lines_list:
if args.all_songs:
crawler = TcrawlTech(j)
res = crawler.search_all_songs(crawler.vagalume_connect())
if res is True:
save = str(
input(
"\nWould you like to save this list as a .txt file? (y/n)\n"
)
).lower()
if save in ["y", "yes", "sim"]:
crawler.save_crawl()
else:
crawler = TcrawlTech(j, args.number)
res = crawler.top_list(crawler.vagalume_connect())
if res is True:
save = str(
input(
"\nWould you like to save this list as a .txt file? (y/n)\n"
)
).lower()
if save in ["y", "yes", "sim"]:
crawler.save_crawl()
if args.as_argument:
if args.all_songs:
crawler = TcrawlTech(args.artist)
res = crawler.search_all_songs(crawler.vagalume_connect())
if res is True:
save = str(
input("\nWould you like to save this list as a .txt file? (y/n)\n")
).lower()
if save in ["y", "yes", "sim"]:
crawler.save_crawl()
else:
crawler = TcrawlTech(args.artist, args.number)
res = crawler.top_list(crawler.vagalume_connect())
if res is True:
save = str(
input("\nWould you like to save this list as a .txt file? (y/n)\n")
).lower()
if save in ["y", "yes", "sim"]:
crawler.save_crawl()
if __name__ == "__main__":
main()