import nflgame
import csv
from apscheduler.schedulers.background import BackgroundScheduler
year = 2013
week = 1
games = nflgame.games(year, week)
players = nflgame.combine_game_stats(games)
ctr = 0
def myjob():
print('This job is run every 2 seconds.')
with open('/Users/lukenolan/Desktop/Python Work/data.csv', 'w') as file:
file.write('%s,%s %s' % (str(year), str(week), '\n'))
for p in players:
print(ctr)
ctr += 1
file.write('%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % (p.playerid, p.player.position, p.name, p.team, p.passing_att, p.passing_cmp, p.passing_yds, p.passing_tds, p.passing_ints, p.passing_sk, p.passing_twoptm, p.passing_yds, p.rushing_att, p.rushing_yds, p.rushing_tds, p.rushing_twoptm, p.rushing_yds_loss, p.receiving_rec, p.receiving_twoptm, p.receiving_yds, p.receiving_tds, p.fumbles_tot, p.fumbles_lost, p.fumbles_rec, p.defense_frec, p.defense_sk, p.defense_int, p.defense_tds, p.defense_safe, p.kicking_fgd, p.punting_blk, p.defense_xpblk, p.kicking_fgm_yards, p.kicking_xpmade, p.kicking_fgmissed))
file.write('\n')
sched = BackgroundScheduler()
sched.add_job(myjob, 'interval', seconds=5)
sched.start()
答案 0 :(得分:0)
与许多其他情况一样,这里发生的是您正在启动后台调度程序,然后退出脚本。这正是BlockingScheduler
的目的。