-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUse this Main.py
40 lines (36 loc) · 1.24 KB
/
Use this 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
import xml.parsers.expat
class mainGenre:
def getGenreLink(self,baseGenre):
genreLink={
'awe':['feminism','historical','biblical','fantasy', 'christian','inspirational','space', 'surreal'],
'action':['action','adventure','war'],
'dark':['dark', 'death','witchcraft','occult'],
'sad':[ 'disability','anthologies'],
'romance':['gender', 'holiday', 'love','relationships', 'romantic', 'social', 'womens'],
'general':['animals', 'diary', 'management', 'medical', 'textbooks', 'wildlife','drama']
}
genreKey=['awe','action','dark','sad','romance','general']
for c in genreKey:
if baseGenre in genreLink[c]:
print(c)
return c
return None
def main():
obj=mainGenre()
p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = obj.start
p.CharacterDataHandler = obj.popularity
p.Parse(obj.stringofxml)
obj.sort()
genresList=["drama","love","datshit"]#link to genres list from api
genre=None
for c in genresList:
genre=obj.getGenreLink(c)#Put genre you get from api
if(genre!=None):
break
if(genre==None):
genre=general
print(obj.genre)
print (obj.number)
if __name__ == "__main__":
main()