def main(): import scriptine try: scriptine.run() except KeyError: print "Unrecognized argument." sys.argv.append("--help") scriptine.run()
def test_foo2(): with stdout_capture() as (stdout, stderr): try: run(args=['test_command.py', 'foo2']) except SystemExit: pass else: assert False, 'did not exit' stderr.seek(0) out = stderr.read() assert 'number of arguments does not match' in out assert 'foo2_command_called' not in state
title, author, ingredients, instructions = bbc_one_command(purl(addr, a.get('href'))) output.append({'title': title, 'author': author, 'ingredients': ingredients, 'instructions': instructions}) print json.dumps(output) def bbc_one_command(url): # One recipe page addr, soup = get_soup(url) title = soup.find('h1').string.encode('utf-8').strip() author = soup.find('span', class_="author").string.encode('utf-8').strip() # Ingredients ingredients = [] for p in soup.find_all("p", class_="ingredient"): text = re.sub('<[^<]+?>', '', p.encode('utf-8').strip()) ingredients.append(text) # Instructions instructions = [] for li in soup.find_all("li", class_="instruction"): p = li.find("p") instructions.append(p.string.encode('utf-8').strip()) # print title, author, ingredients, instructions return title, author, ingredients, instructions # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # if __name__ == '__main__': import scriptine scriptine.run()
prompt = "Enter the value associated with {key} for {service} : " prompt = prompt.format(service=service, key=key) return getpass.getpass(prompt) def get(service, key, read_only=False): """ Returns the value associated with key for the service. If the value is not found, prompts the user for the value, saves it and returns it. If the value is not found and read_only is True, returns None. """ value = keyring.get_password(service, key) if value is None and not read_only: value = ask(service, key) set(service, key, value) # If running via command line, print it. if __name__ == '__main__' and value: print value return value if __name__ == '__main__': import scriptine get_command = get set_command = set scriptine.run()
Compile an emacs file FN """ sh_cmdln("emacs -Q -l epy-init.el -batch -f batch-byte-compile",[fn]) def clean(): """TODO: Clean the build stuff etc... """ # removing compiled files [rm(f) for f in find("*.pyc")] [rm(f) for f in find("*.elc")] rm("dist") def package_command(): """Package the emacs-for-python distribution """ clean() GLOBS = "COPYING README.org epy-*.el extensions\ doc python-libs scripts".split() # Concatenating lists FILES = itertools.chain(*(glob.glob(g) for g in GLOBS)) mkdir("dist/emacs-for-python-"+VERSION,parent=True) [cp(f,"dist/emacs-for-python-"+VERSION) for f in FILES] archive(["dist/emacs-for-python-"+VERSION], "dist/emacs-for-python-%s.tar.gz"%VERSION,format="gzip") if __name__ == '__main__': run()
def test_foo2_w_arg(): run(args=['test_command.py', 'foo2', 'buzz']) assert 'foo2_command_called_with_buzz' in state
def test_foo1(): run(args=['test_command.py', 'foo1']) assert 'foo1_command_called' in state
users = users.drop(idx) elif api.LastResponse.status_code == 429: logger.info('Waiting 5 minutes due to request limit') sleep(300) else: Exception( f'Unrecognized response code: {api.LastResponse.status_code}') new_data = new_data.set_index('idx') users.update(new_data) write_users(users) def update_followers_command(): update_followers() def check_responses_of_follows_command(): check_responses_of_follows() def scrape_new_users_command(): scrape_new_users() def retrieve_additional_information_command(): retrieve_additional_information() if __name__ == "__main__": run()
def main(): run()