gpt4 book ai didi

python - IMDBpy 获取屏幕信息

转载 作者:行者123 更新时间:2023-12-01 05:52:18 36 4
gpt4 key购买 nike

import imdb    
ia = imdb.IMDb()
avatar = ia.get_movie("0120667")
ia.update(avatar, 'business')
print avatar['business']

这将返回整个总票房列表以及每个国家/地区的放映次数。但如何只获取筛选信息呢?并且仅适用于 1 个国家/地区。在此示例中,我想要获取的信息是(美国)(2005 年 7 月 10 日)(3,602 个屏幕)

最佳答案

import imdb
import re

ia = imdb.IMDb()
avatar = ia.get_movie("0120667")
ia.update(avatar, 'business')
opening_weekends = avatar['business']['opening weekend']

def parseDate(date):
result = {}

if re.match(".*\d{4}$", date):
result['year'] = date[-4:]

m = re.match(".*(?P<month>January|February|March|April|May|June|July|"
"August|September|October|November|December).*", date, re.I)
if m:
result['month'] = m.group('month').lower()

# try to grab date too then
daymatch = re.match("^(?P<day>\d{1,2}).*", date)

if daymatch:
result['day'] = daymatch.group('day')
return result

def parseBudget(amount):
"""
assumptions:
- currency is always before the number
- no fractions
"""

# find index first number
for i in range(len(amount)):
if amount[i] in "0123456789":
amount_idx = i
break

currency = amount[:amount_idx].strip()
amount = re.sub("\D", "", amount[amount_idx:])

return amount, currency

def parseWeekendGross(gross_text):
g = gross_text.split(' (')
if not len(g) == 4:
return ""
amount, currency = parseBudget(g[0])
country = g[1].lstrip('(').rstrip(')')
date = parseDate(g[2].lstrip('(').rstrip(')'))
day, month, year = date['day'], date['month'], date['year']
screens = re.sub("\D", "", g[3])
if not screens:
screens = "''"

return amount, currency, country, day, month, year, screens

for entry in opening_weekends:
amount, currency, country, day, month, year, screens = parseWeekendGross(entry)
if country == "USA":
print("Country: %s" % country)
print("Date: %s %s %s" % (day, month, year))
print("Screens: %s" % screens)
break

上面的代码给出了以下结果:

Country: USA
Date: 10 july 2005
Screens: 3602

解析数据的函数是从该项目复制的:pyIRDG

关于python - IMDBpy 获取屏幕信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13741561/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com