def test_popdb_date(self): "Test popdb_date method" result = popdb_date('20140105') expect = '2014-1-5' self.assertEqual(expect, result) result = popdb_date(expect) self.assertEqual(expect, result)
def main(): "Main function" optmgr = OptionParser() opts, _ = optmgr.get_opt() if opts.verbose: print(time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())) time0 = time.time() mgr = DCAF(opts.config, opts.verbose) if opts.clean: mgr.cleanup('cache') return if opts.docid: mgr.remove('cache', opts.docid) return if opts.update: mgr.update() return if opts.start or opts.stop: tframe = [popdb_date(opts.start), popdb_date(opts.stop)] else: tframe = None fout = opts.fout seed = opts.seed dformat = opts.dformat dbsextra = opts.dbs_extra newdata = opts.newdata fout = opts.fout def run(fout, tframe, seed, dformat, dbsextra, newdata): with fopen(opts.fout, 'w') as ostream: for row in mgr.dataframe(tframe, seed, dformat, dbsextra, newdata): ostream.write(row + '\n') if opts.profile: import cProfile # python profiler import pstats # profiler statistics cmd = 'run(fout,tframe,seed,dformat,dbsextra,newdata)' cProfile.runctx(cmd, globals(), locals(), 'profile.dat') info = pstats.Stats('profile.dat') info.sort_stats('cumulative') info.print_stats() else: run(fout, tframe, seed, dformat, dbsextra, newdata) if opts.verbose: print("Elapsed time:", datetime.timedelta(seconds=(time.time() - time0))) print(time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())) verify_csv(fout, opts.verbose)
def main(): "Main function" optmgr = OptionParser() opts, _ = optmgr.get_opt() if opts.verbose: print(time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())) time0 = time.time() mgr = DCAF(opts.config, opts.verbose) if opts.clean: mgr.cleanup('cache') return if opts.docid: mgr.remove('cache', opts.docid) return if opts.update: mgr.update() return if opts.start or opts.stop: tframe = [popdb_date(opts.start), popdb_date(opts.stop)] else: tframe = None fout = opts.fout seed = opts.seed dformat = opts.dformat dbsextra = opts.dbs_extra newdata = opts.newdata fout = opts.fout def run(fout, tframe, seed, dformat, dbsextra, newdata): with fopen(opts.fout, 'w') as ostream: for row in mgr.dataframe(tframe, seed, dformat, dbsextra, newdata): ostream.write(row+'\n') if opts.profile: import cProfile # python profiler import pstats # profiler statistics cmd = 'run(fout,tframe,seed,dformat,dbsextra,newdata)' cProfile.runctx(cmd, globals(), locals(), 'profile.dat') info = pstats.Stats('profile.dat') info.sort_stats('cumulative') info.print_stats() else: run(fout, tframe, seed, dformat, dbsextra, newdata) if opts.verbose: print("Elapsed time:", datetime.timedelta(seconds=(time.time()-time0))) print(time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())) verify_csv(fout, opts.verbose)
def main(): optmgr = OptionParser() opts, _ = optmgr.get_opt() popdb_datasets(popdb_date(opts.tstart), popdb_date(opts.tstop), opts.url)