匈牙利电影城api的python接口。
pycin的Python项目详细描述
匈牙利电影城的python api
这个框架为电影城数据api提供了一个python接口。通过调用fetch_events([dates], [locations])
,可以从api查询特定时间和位置的事件。查询中的数据存储为嵌套dto的iterable,如下所示。Cinema
带有id
(str
,场馆的唯一标识符)的对象。和name
(str
,场馆名称。)属性。Movie
对象带有id
(str
,电影的唯一标识符。),name
(str
,场馆名称。),attributes
(tuple
,电影特定信息,如配音或3d.)和length
(int
,电影长度(分钟)。。Event
对象具有id
(str
,事件的唯一标识符。),date
(datetime
,电影放映开始时间。),booking_link
(str
,机票预订链接的url。),sold_out
(bool
,票的可用性。),movie
(Movie
,放映的电影,存储为Movie
对象。),cinema
(Cinema
,事件的位置,存储为Cinema
对象。)和attributes
(tuple
,电影特定信息,如配音或3d。)。
用法
直接从这个git存储库使用pip或使用以下命令之一从pypi安装包是很简单的。
pip install git+https://github.com/Mrpatekful/pycin
pip install pycin尽管该软件包包含所有电影院位置,作为电影DTO常量,但这些信息可能过时了。
fetch_cinemas
方法总是返回最新的电影数据。frompycinimportfetch_cinemascinemas=fetch_cinemas()print(cinemas)
[Cinema(id='1124', name='Alba - Székesfehérvár'), Cinema(id='1133', name='Allee - Budapest'), Cinema(id='1132', name='Aréna - Budapest'), Cinema(id='1131', name='Balaton - Veszprém'), Cinema(id='1139', name='Campona - Budapest'), Cinema(id='1127', name='Debrecen'), Cinema(id='1141', name='Duna Pláza - Budapest'), Cinema(id='1125', name='Győr'), Cinema(id='1129', name='Miskolc'), Cinema(id='1143', name='Nyíregyháza'), Cinema(id='1128', name='Pécs'), Cinema(id='1134', name='Savaria - Szombathely'), Cinema(id='1136', name='Sopron'), Cinema(id='1126', name='Szeged'), Cinema(id='1130', name='Szolnok'), Cinema(id='1137', name='Westend - Budapest'), Cinema(id='1135', name='Zalaegerszeg')]
在电影院获取事件alle,westend,其中放映的电影具有id3196o2r。
fromdatetimeimportdatetimefrompycinimportfetch_events,ALLE,WESTENDquery=fetch_events([datetime.today()],[ALLE,WESTEND])result=list(query.filter(lambdae:e.movie.id=='3196o2r').select(lambdae:(e.date,e.cinema.name)))print(result)
[(datetime.datetime(2019, 2, 28, 17, 40), 'Allee - Budapest'), (datetime.datetime(2019, 2, 28, 19, 50), 'Allee - Budapest'), (datetime.datetime(2019, 2, 28, 22, 0), 'Allee - Budapest'), (datetime.datetime(2019, 2, 28, 17, 20), 'Alba - Székesfehérvár'), (datetime.datetime(2019, 2, 28, 19, 30), 'Alba - Székesfehérvár')]
找到唯一的一组电影,它们将在下周晚上8:00后在布达佩斯的任何一个电影城播放(因为fetch_events
的默认位置是BUDAPEST_CINEMAS
)。
frompycinimportfetch_eventsfromdatetimeimportdatetime,timedeltanext_week=[datetime.today()+timedelta(d)fordinrange(7)]query=fetch_events(next_week)result=set(query.filter(lambdae:e.date.hour>20).select(lambdae:e.movie.name))print(result)
{'Kölcsönlakás', 'Cold Pursuit', 'Happy DeathDay 2U', 'Instant Family', 'Heavy Trip (Hevi Reissu)', 'Sink or Swim (Le grand bain)', 'Alita: Battle Angel', 'Most van most', 'En Liberté (The Trouble with You)', 'Bohemian Rhapsody', 'Vice', 'Apró mesék', 'Green Book', 'Drunk Parents', 'The Prodigy', 'Captain Marvel', 'Glass', 'Fighting with My Family'}
在第一次调用时,search_events
可能需要更长的时间才能执行,但结果被缓存,因此使后续调用立即产生结果。
importloggingfromdatetimeimportdatetimefrompycinimportfetch_events# Setting up logging to the console.console=logging.StreamHandler()formatter=logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')console.setFormatter(formatter)logger.addHandler(console)deflist_dates(dates,cinemas):"""Finds screening dates of 2d movies with the word `marvel` in their title."""query=fetch_events(dates,cinemas)returnlist(query.filter(lambdae:'2d'ine.attributesand \ 'marvel'ine.movie.name.lower()).select(lambdae:datetime.strftime(e.date,'%H:%M')))list_dates([datetime.today()],[ALLE])# second call is instantaneous because of cached resultsresult=list_dates([datetime.today()],[ALLE])print(result)
2019-03-12 11:38:16,454 - DEBUG - Query finished in 0.9281s. 2019-03-12 11:38:16,466 - DEBUG - Query finished in 0.0000s. ['13:20', '16:00', '16:50', '18:40', '19:30', '21:20', '22:10']