def main(): try: import clime except ImportError: clime = None if clime: clime.start({'calendar': git_calendar}) else: raise Exception("I need clime.")
def main(): try: import clime except ImportError: clime = None if clime and clime.__version__ >= '0.2': clime.start({'count': count}) else: import sys print >> sys.stderr, 'It works better with Clime (>= 0.2). Visit http://clime.mosky.tw/ for more details.' if len(sys.argv) <= 1: count() else: count(sys.argv[1])
response = BidResponse() ofile = gzip.GzipFile(ofile, 'w') for line in buf_read(io): try: m = pattern.findall(line) if m: time, req, resp = m[0] request.ParseFromString(req) response.ParseFromString(resp) req = pb2json(request) resp = pb2json(response) # add some reference property req['time'] = time req['_type'] = 'BidRequest' resp['time'] = time resp['request_id'] = req['id'] resp['_type'] = 'BidResponse' ofile.write(json.dumps(req) + '\n') ofile.write(json.dumps(resp) + '\n') except: pass import re if __name__ == "__main__": import clime; clime.start(default="convert")
#!/usr/bin/env python # -*- coding: utf-8 -*- def reverse(string): '''reverse string ''' print string.decode('UTF-8')[::-1] if __name__ == '__main__': # > v0.2 import clime clime.start(ignore_return=True) # >= v0.1.6 #import clime #clime.customize(ignore_return=True) # It also works, because the ``reverse`` returns noting. #import clime.now
for row in ireader: if not row['Sponsor Package']: continue level = row['Sponsor Package'].split()[0] if level not in level_orders: logging.warning("not recognize level %s", level) continue name = row["Sponsor Name"].decode('utf8') logo = upload_image(row["Sponsor Logo Image"]) description = row["Sponsor Description"].decode('utf8') sponsor_categories[level].append({ "name": name, "level": level, "logo": logo, "description": description }) sponsor_categories = [{ "level":k, "sponsors": sponsor_categories[k] } for k in level_orders] html = template.render(sponsor_categories=sponsor_categories) with open('sponsor_page.gen.html', 'w') as ofile: ofile.write(html.encode('utf8')) if __name__ == '__main__': import clime; clime.start(debug=True)
def say(word, name=None): if name: print '%s, %s!' % (word, name) else: print '%s!' % word def hi_cmd(name=None): say('Hi', name) def hello_cmd(name=None): say('Hello', name) if __name__ == '__main__': import clime clime.start(white_pattern=clime.CMD_SUFFIX) ########NEW FILE######## __FILENAME__ = lineno #!/usr/bin/env python # -*- coding: utf-8 -*- import sys def lineno(start=0): for i, line in enumerate(sys.stdin, start): sys.stdout.write('%3d| %s' % (i, line)) if __name__ == '__main__': import clime.now
ofile.write(template.render({ 'img': img, 'rows': new_rows }).encode('utf8')) def main(): with open('results.csv', 'w') as ofile: writer = csv.DictWriter(ofile, ( 'title', 'link', 'type', 'contact', 'place', 'lat', 'lng', 'address', 'size', 'price', 'img') ) writer.writeheader() for i in parse(6): writer.writerow(i) for i in parse(12): writer.writerow(i) if __name__ == '__main__': import clime clime.start(debug=True)
def parseTextContracts_cmd(where=None, limit=None): """Command that runs process to extract data from a text based contract using Poppler.""" docformat = st.DOCFORMAT_CONTRACT query = queries.idOnly('T', docformat, where, limit) process = parseTextContracts() bulkProcess(process, query, abortOnError=False) def parseTextInvoices_cmd(where=None, limit=None): """Command that runs process to extract data from a text based invoice using Poppler.""" docformat = st.DOCFORMAT_INVOICE query = queries.idOnly('T', docformat, where, limit) process = parseTextInvoices() bulkProcess(process, query, abortOnError=False) def parseTextOrders_cmd(where=None, limit=None): """Command that runs process to extract data from a text based order using Poppler.""" docformat = st.DOCFORMAT_ORDER query = queries.idOnly('T', docformat, where, limit) process = parseTextOrders() bulkProcess(process, query, abortOnError=False) if __name__ == '__main__': import clime clime.start(white_pattern=clime.CMD_SUFFIX, debug=True)
addinfo = '' if not noinfo: addinfo = ''' | sed -e "s|\(.\+\)$|\\1\\t{8}\\t%(page)i\\t%(extract_params)s\\t{1}\\t{2}\\t{3}\\t{4}\\t{5}\\t{6}\\t{7}\\t{8}|g" ''' % locals() addinfo += '\'' # quote for end of parallel section if outfile is not None: output_file = '''> %(outfile)s ''' % locals() cmd = ' '.join([pdfpaths, parallel, ghostscript, convert_resize, cropbox, convert_crop, textcleaner_arg, threshold_arg, ocr, remove_nl, addinfo, output_file]) if printcmd: print(cmd) else: cmdout = osutil.getStdoutFromCmd(cmd, shell=True) if cmdout.strip() != '': print cmdout # remove cuneiform output files filelist = glob.glob("/tmp/*cuneiform.txt") for f in filelist: os.remove(f) if __name__ == '__main__': import clime clime.start(white_pattern=clime.CMD_SUFFIX, doc=__doc__, default='run', debug=False)
#Load plugin module plugin_module = load_module(module_name, *find_module(plugin_name, [module_path])) #Get the command method and set it to command object methods = dir(plugin_module) for method in methods: if method.endswith("cmd"): method_obj = getattr(plugin_module, method) setattr(cmd_obj, method, method_obj) return plugin_module def __load_module_from_package(package): #Find all python file in the package file package_path = os.path.join(plugins_root, package) plugin_files = os.listdir(package_path) if __name__ == '__main__': __import_plugin_cmd("cli" ,"hello") import clime clime.start(white_pattern=clime.CMD_SUFFIX, debug=True)
all_p = dict(p.items() + cl_params.items()) if i == 0: all_p['inputfile'] = inputfile #all_p['where'] = "and ep.params='%(b_params)s'" % b_params else: all_p['inputfile'] = invalidfile all_p['outfile'] = "%s%s_%i.tsv" % (st.to_validate_dir, targetfield, i) invalidfile = "%s%s_%i.tsv" % (st.invalid_data_dir, targetfield, i) if i == len(p) - 1: all_p['outputpng'] = True all_p['outputcrop'] = True all_p['outputchop'] = True rp.run_cmd(**all_p) osutil.getStdoutFromCmd( '''cat %s | python %svalidate.py %s > %s ''' % (all_p['outfile'], st.python_bin, validfile, invalidfile), shell=True) if __name__ == '__main__': import clime clime.start(white_pattern=clime.CMD_SUFFIX, default='run_extract', debug=True)
print '%s, %s!' % (word, name) else: print '%s!' % word def hi_cmd(name=None): say('Hi', name) def hello_cmd(name=None): say('Hello', name) if __name__ == '__main__': import clime clime.start(white_pattern=clime.CMD_SUFFIX) ########NEW FILE######## __FILENAME__ = lineno #!/usr/bin/env python # -*- coding: utf-8 -*- import sys def lineno(start=0): for i, line in enumerate(sys.stdin, start): sys.stdout.write('%3d| %s' % (i, line)) if __name__ == '__main__':
def main(): import clime from gmachine import cmd clime.start(obj=cmd, black_list=["main", "local"])
from __future__ import print_function try: bytes except NameError: bytes = str str = unicode def reverse(x): '''We assume it is a helper function for something else. It returns True to let other stuff work. ''' if not isinstance(x, (bytes, str)): x = str(x) if isinstance(x, bytes): x = x.decode('utf-8') print(x[::-1]) return x if __name__ == '__main__': import clime clime.start(ignore_return=True, debug=True)
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import print_function try: bytes except NameError: bytes = str str = unicode def reverse(x): '''We assume it is a helper function for something else. It returns True to let other stuff work. ''' if not isinstance(x, (bytes, str)): x = str(x) if isinstance(x, bytes): x = x.decode('utf-8') print(x[::-1]) return x if __name__ == '__main__': import clime clime.start(ignore_return=True, debug=True)
chp_csv_path = _chp_csv_path if db_path is None: db_path = _db_path # build the index dir_ = Directory(db_path) with open(chp_csv_path, 'rb') as csv_f: dir_.load_chp_csv(csv_f) def build_cmd(chp_csv_path=None, db_path=None): '''Build a ZIP code index by the CSV from Chunghwa Post. -i, --chp-csv-path The path of the CSV. -o, --db-path The output path. ''' print('Building ZIP code index ...', end=' ') sys.stdout.flush() build(chp_csv_path, db_path) print('Done.') if __name__ == '__main__': try: import clime except ImportError: build(*sys.argv[1:]) else: clime.start(white_pattern=clime.CMD_SUFFIX)
if not row['Sponsor Package']: continue level = row['Sponsor Package'].split()[0] if level not in level_orders: logging.warning("not recognize level %s", level) continue name = row["Sponsor Name"].decode('utf8') logo = upload_image(row["Sponsor Logo Image"]) description = row["Sponsor Description"].decode('utf8') sponsor_categories[level].append({ "name": name, "level": level, "logo": logo, "description": description }) sponsor_categories = [{ "level": k, "sponsors": sponsor_categories[k] } for k in level_orders] html = template.render(sponsor_categories=sponsor_categories) with open('sponsor_page.gen.html', 'w') as ofile: ofile.write(html.encode('utf8')) if __name__ == '__main__': import clime clime.start(debug=True)
for root, dirs, files in os.walk(dir_path.decode("cp950")): failed_files = filter(lambda n: n.endswith('-failed.pdf'), files) for failed_file in failed_files: fullpath = os.path.join(root, failed_file) try: reset_filename(fullpath) except WindowsError: print [fullpath] def download(target_id): browser = webdriver.Ie() part1_login(browser) loggedin_cookies = cookies_to_dict(browser.get_cookies()) get_profile_url = 'https://social.ntpc.gov.tw/jsp/G/SWJG010.jsp?update=1231231123' get_profile_formdata = 'actionType=query&primarykey1=&primarykey2=&primarykey3=&P_QUERYTYPE=G010&P_USERDOWNTN=10100010&P_ALLTITLES=11003005&P_LIMITCONTROL=townApply&P_FDYYY=&P_CHECKFLAG0=0&P_CHECKFLAG=&P_WFNO1=&P_WFNO2=&P_TBHEAD=W00&view_P_APPDTS=&P_APPDTS=&view_P_APPDTE=&P_APPDTE=&P_IDNO=F290211348&P_NAME=&P_DOWNTN=&P_AREA=&view_P_WSDTS=&P_WSDTS=&view_P_WSDTE=&P_WSDTE=&P_APPDOWNTN=&P_APPIDNO=&view_P_ALLOTDTSY=&view_P_ALLOTDTSM=&P_ALLOTDTS=&view_P_ALLOTDTEY=&view_P_ALLOTDTEM=&P_ALLOTDTE=&P_CHK539=&view_P_DOCDT=&P_DOCDT=&P_DOCNO=' resp_caselist = requests.post(get_profile_url, data=get_profile_formdata, cookies=loggedin_cookies, verify=False) print resp_caselist.text if __name__ == '__main__': import clime clime.start(white_list=['upload', 'download', 'batchupload', 'reset_fail'], debug=DEBUG)
def application(env, start_response): path = env['PATH_INFO'] qs = env['QUERY_STRING'] logger.info(path + "?" + qs) start_response('204 No Content', []) return [] class LogServer(gevent.server.DatagramServer): def handle(self, data, address): logger.info(data) def start(type="TCP", port=8080, filename="request.log", when="H"): config = yaml.load(open('conf.yaml', 'r').read().format(**{ "filename": filename, "when": when })) logging.config.dictConfig(config) if type == "TCP": WSGIServer(('', port), application).serve_forever() else: LogServer(":%s" % port).serve_forever() if __name__ == '__main__': import clime; clime.start() # start('tagtoo_rtb_log', type="UDP")
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import print_function def say(word, name=None): if name: print('%s, %s!' % (word, name)) else: print('%s!' % word) def hi_cmd(name=None): say('Hi', name) def hello_cmd(name=None): say('Hello', name) if __name__ == '__main__': import clime clime.start(white_pattern=clime.CMD_SUFFIX)
min_percent_ratio_score = aratio_diffs[close_percent] if min_ratio_score * min_ratio_percent_score < min_percent_score * min_percent_ratio_score: b_index = close_ratio else: b_index = close_percent else: b_index = close_ratio # They're the same b = blobs[b_index] minx = minX(b) miny = minY(b) maxx = maxX(b) maxy = maxY(b) imgc = imgc[minx:maxx, miny:maxy] imout = np.uint8(imgc) out = Image.fromarray(imout) out.save(sys.stdout, format='PNG') if __name__ == '__main__': import clime clime.start(white_pattern=clime.CMD_SUFFIX, doc=__doc__, default='run', debug=False)
validfile = "%s%s.tsv" % (st.raw_data_dir, targetfield) else: validfile = validfile for i, p in enumerate(st.extract_params): all_p = dict(p.items() + cl_params.items()) if i == 0: all_p['inputfile'] = inputfile #all_p['where'] = "and ep.params='%(b_params)s'" % b_params else: all_p['inputfile'] = invalidfile all_p['outfile'] = "%s%s_%i.tsv" % (st.to_validate_dir, targetfield, i) invalidfile = "%s%s_%i.tsv" % (st.invalid_data_dir, targetfield, i) if i == len(p) - 1: all_p['outputpng'] = True all_p['outputcrop'] = True all_p['outputchop'] = True rp.run_cmd(**all_p) osutil.getStdoutFromCmd('''cat %s | python %svalidate.py %s > %s ''' % (all_p['outfile'], st.python_bin, validfile, invalidfile), shell=True) if __name__ == '__main__': import clime clime.start(white_pattern=clime.CMD_SUFFIX, default='run_extract', debug=True)