匈牙利电影城api的python接口。

pycin的Python项目详细描述


匈牙利电影城的python api

这个框架为电影城数据api提供了一个python接口。通过调用fetch_events([dates], [locations]),可以从api查询特定时间和位置的事件。查询中的数据存储为嵌套dto的iterable,如下所示。Cinema带有idstr,场馆的唯一标识符)的对象。namestr,场馆名称。)属性。Movie对象带有idstr,电影的唯一标识符。)namestr,场馆名称。)attributestuple,电影特定信息,如配音或3d.)lengthint,电影长度(分钟)。Event对象具有idstr,事件的唯一标识符。)datedatetime,电影放映开始时间。)booking_linkstr,机票预订链接的url。)sold_outbool,票的可用性。)movieMovie,放映的电影,存储为Movie对象。)cinemaCinema,事件的位置,存储为Cinema对象。)attributestuple,电影特定信息,如配音或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')]

在电影院获取事件allewestend,其中放映的电影具有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']

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
图形Java仿射变换以旋转通用路径   IntelliJ IDEA中的java代码标记为编译器错误,在Eclipse中可以正常工作   java ArrayList的containsAll返回了错误的值   如何在安卓中的片段活动中添加java代码   java通过使用netbeans调用jbutton,将带有行的jbutton添加到jtable中   java在更新arrayAdapter/listView之前更新最终列表   java如何在另一个项目中导入包含AspectJ方面和注释的项目   为什么我的java布尔测试总是失败?   Eclipse中的java自动激活   在Bluetooth for Java(更具体地说是Android)之上是否有TCP/IP协议栈实现?   java Android Studio通过intent传递ArrayList并填充ListView