本文整理汇总了Python中feed.Feed.load_and_prepare方法的典型用法代码示例。如果您正苦于以下问题:Python Feed.load_and_prepare方法的具体用法?Python Feed.load_and_prepare怎么用?Python Feed.load_and_prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feed.Feed
的用法示例。
在下文中一共展示了Feed.load_and_prepare方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_headlines
# 需要导入模块: from feed import Feed [as 别名]
# 或者: from feed.Feed import load_and_prepare [as 别名]
def load_headlines():
global headlines_url
global response_headline
global headlines_data
global stories
headlines_url = "http://sanfrancisco.giants.mlb.com/gen/sf/news/headlines.json"
feed = Feed(headlines_url)
feed.load_and_prepare()
succeeded, loaded_headlines_json = feed.get_representation
length = len(loaded_headlines_json["members"])
story_elements = []
story_blurbs = []
story_url = []
for index in range(length):
story_elements.append(loaded_headlines_json["members"][index])
length = len(story_elements)
stories = []
for index in range(length):
try:
item = NewsItem(story_elements[index]["althead"], story_elements[index]["url"])
stories.append(item)
except:
print "No althead or url found at index %d; skipping to next item..." % index
continue
示例2: get_scoreboard_info
# 需要导入模块: from feed import Feed [as 别名]
# 或者: from feed.Feed import load_and_prepare [as 别名]
def get_scoreboard_info():
global year
global month
global day
global giants_pitcher_name
global giants_pitcher_era
global end_game_message
global current_game_status
global current_game_inning
master_scoreboard_url = "http://mlb.mlb.com/gdcross/components/game/mlb/year_%s/month_%s/day_%s/master_scoreboard.json" % (year, str(month).zfill(2), str(day).zfill(2))
feed = Feed(master_scoreboard_url)
feed.load_and_prepare()
succeeded, loaded_schedule_json = feed.get_representation
schedule_list = loaded_schedule_json["data"]["games"]["game"]
send = client.sock.send
for game in schedule_list:
try:
if game["away_team_name"] == "Giants" or game["home_team_name"] == "Giants":
current_game_status = game["alerts"]["brief_text"]
# if "Middle 7th" in game["alerts"]["brief_text"]:
# msg = "PRIVMSG " + input[2] + " :" + "When the lights.. go down.. in the cityyy... https://www.youtube.com/watch?v=tNG62fULYgI" "\r\n"
# send(msg) # https://www.youtube.com/watch?v=tNG62fULYgI
except:
if "winning_pitcher" in game and (game["home_team_name"] == "Giants" or game["away_team_name"] == "Giants"):
winning_pitcher = "%s %s" % (game["winning_pitcher"]["first"], game["winning_pitcher"]["last"])
losing_pitcher = "%s %s" % (game["losing_pitcher"]["first"], game["losing_pitcher"]["last"])
end_game_message = "Game over. Winning pitcher: %s. Losing pitcher: %s." % (winning_pitcher, losing_pitcher)
current_game_status = ""
else:
current_game_status = "No active game."
if game["away_team_name"] == "Giants":
if "away_probable_pitcher" in game:
giants_pitcher_name = "%s %s" % (game["away_probable_pitcher"]["first"], game["away_probable_pitcher"]["last"])
giants_pitcher_era = game["away_probable_pitcher"]["era"]
return
elif "opposing_pitcher" in game:
giants_pitcher_name = "%s %s" % (game["opposing_pitcher"]["first"], game["opposing_pitcher"]["last"])
giants_pitcher_era = game["opposing_pitcher"]["era"]
return
elif game["home_team_name"] == "Giants":
if "home_probable_pitcher" in game:
giants_pitcher_name = "%s %s" % (game["home_probable_pitcher"]["first"], game["home_probable_pitcher"]["last"])
giants_pitcher_era = game["home_probable_pitcher"]["era"]
return
elif "pitcher" in game:
giants_pitcher_name = "%s %s" % (game["pitcher"]["first"], game["pitcher"]["last"])
giants_pitcher_era = game["pitcher"]["era"]
return
示例3: print_today
# 需要导入模块: from feed import Feed [as 别名]
# 或者: from feed.Feed import load_and_prepare [as 别名]
def print_today():
full_date = "%s/%s/%s/" % (year, str(month).zfill(2), str(day).zfill(2))
# print "%d %d %d" % (today[0], today[1], today[2])
global today_game
schedule_url = "http://sanfrancisco.giants.mlb.com/gen/schedule/sf/%s_%s.json" % (year, month)
feed = Feed(schedule_url)
feed.load_and_prepare()
succeeded, loaded_schedule_json = feed.get_representation
response_schedule = urllib2.urlopen(schedule_url)
schedule_data = json.load(response_schedule)
schedule_data = json.dumps(schedule_data, sort_keys=True, indent=4, separators=(',', ': ')) # pretty printed json file object data
loaded_schedule_json = json.loads(schedule_data)
start_time = ""
for entry in loaded_schedule_json:
try:
if full_date in entry["game_id"]:
versus = entry["away"]["full"] + " @ " + entry["home"]["full"]
if entry["away"]["full"] == "Giants":
start_time = entry["away"]["start_time_local"]
home = False
else:
start_time = entry["home"]["start_time_local"]
start_time = start_time[11:]
start_time = start_time[:5]
t = time.strptime(start_time, "%H:%M")
new_start_time = time.strftime("%I:%M %p", t)
# print versus + " starting at " + new_start_time
today_game = versus + " starting at " + new_start_time
except:
continue
示例4: parse_lineup_feed
# 需要导入模块: from feed import Feed [as 别名]
# 或者: from feed.Feed import load_and_prepare [as 别名]
def parse_lineup_feed():
global starting_lineup_feed
global team_id
global lineup
get_todays_date()
starting_lineup_feed = "http://sanfrancisco.giants.mlb.com/gen/lineups/%s/%s/%s.json" % (year, str(month).zfill(2), str(day).zfill(2))
feed = Feed(starting_lineup_feed)
feed.load_and_prepare()
succeeded, loaded_lineup_data = feed.get_representation
global players
if succeeded == False:
players = None
return
lineups_dict = loaded_lineup_data["list"]
for entry in lineups_dict:
# print "%s" % entry
# print "%s" % entry["team_id"]
if entry["team_id"] == team_id:
lineup = entry
break
pos = 1
if "players" in lineup:
for player in lineup["players"]:
name_pos = "%d. %s (%s)" % (pos, player.get("last_name"), player.get("position"))
players.append(name_pos)
pos += 1
players = ", ".join(players)
else:
print "Players not found."
players = None
return