Beispiel #1
0
def main():
	parser = optparse.OptionParser()
	parser.add_option('-v', '--verbose', action='store_true')
	opts,args = parser.parse_args()

	util.ensureDir(GITHUB_EVENTS_DIR)

	io_loop = tornado.ioloop.IOLoop()
	pc = tornado.ioloop.PeriodicCallback(
		lambda:	util.github_request('/events?per_page=100', functools.partial(handle_request, datetime.datetime.utcnow(), opts), io_loop=io_loop),
		INTERVAL, io_loop=io_loop)
	pc.start()
	io_loop.start()
Beispiel #2
0
def main():
	d = github_events.GITHUB_EVENTS_DIR
	backupDir = os.path.join(d, 'backups')
	files = os.listdir(d)
	today = datetime.datetime.utcnow().date()

	byDate = collections.defaultdict(list)
	for f in filter(lambda fn: fn.endswith('.json'), files):
		assert f.startswith('events-')
		date = util.extractDate(f)
		if date < today:
			byDate[date.isoformat()].append(f)
	if byDate:
		util.ensureDir(backupDir)
		for date,files in byDate.items():
			tarfn = os.path.join(d, 'events-' + date + '.tar.bz2')
			assert not os.path.exists(tarfn)
			with contextlib.closing(tarfile.open(tarfn, 'w:bz2')) as tf:
				for f in files:
					fn = os.path.join(d, f)
					tf.add(fn, f, recursive=False)
			for f in files:
				os.rename(os.path.join(d, f), os.path.join(backupDir, f))