def run(): conf = { '/': { 'tools.sessions.on': True, 'tools.caching.on': False, # 'tools.auth_basic.on': True, # 'tools.auth_basic.realm':'admin', # 'tools.auth_basic.checkpassword':encrypt_pwd, 'tools.staticdir.root': config._ROOT_DIR_ }, '/static': { 'tools.staticdir.on': True, 'tools.staticdir.dir': config._STATIC_DIR_ }, '/bootstrap': { 'tools.staticdir.on': True, 'tools.staticdir.dir': config._STATIC_DIR_ + 'bootstrap/css/' }, '/favicon.ico': { 'tools.staticfile.on': True, 'tools.staticfile.filename': favicon() } } with PidFile('server.pid') as spid: print(spid.pidname) print(spid.piddir) portNumber = config.port() cherrypy.config.update({ 'server.socket_host': '0.0.0.0', 'server.socket_port': portNumber, }) cherrypy.quickstart(Notes(), '/', conf)
def main(args): if args.init: flask_app.db.drop_all() flask_app.db.create_all() # in order to generate a self signed certificate (for the scope of this project it is good enough) you can run # openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365 flask_app.app.run(ssl_context=(config.certificate_path(), config.certificate_key_path()), port=config.port())
def establish(): my_region = RegionInfo(name=config.region(), endpoint=config.endpoint()) conn = boto.connect_ec2( aws_access_key_id=config.aws_access_key_id(), aws_secret_access_key=config.aws_secret_access_key(), is_secure=True, region=my_region, port=config.port(), path=config.endpoint_path(), validate_certs=False) return conn
def info(): jsonString = { "app_name": "flask_app", "version": config.git_version(), "git_commit_sha": config.git_commit_sha(), "environment": [{ "service_port": config.port() }, { "log_level": config.log_level() }] } return jsonify(jsonString), 200
def main(): """Serve up a webpage on localhost.""" app.secret_key = config.db_password() app.run(config.ip_address(), port=config.port(), debug=True)
def main(): global Verbose ## mort: this config stuff is a bit grim - really need a proper ## plugin interface configfile = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "perscon", "perscon.conf") config.parse(configfile) uri = "http://localhost:%d/" % (config.port(),) Perscon_utils.init_url(uri) service = "twitter.com" username, password = Perscon_utils.get_credentials(service) ## mort: also note that by using Basic authentication the ## username/password pair are essentially being passed in the clear t = twitter.Twitter(username, password) ## 1. tweets mentioning us tsearch = twitter.Twitter(username, password, domain="search.twitter.com") pg = 1 while True: rs = retryOnError("search pg=%d" % pg, lambda: tsearch.search(rpp=90, page=pg, q=username)) if len(rs['results']) == 0: break stash_tweets(service, username, rs['results']) pg += 1 ## 2. our own tweets pg = 1 while True: rs = retryOnError("own_tweets %d" % (pg,), lambda: t.statuses.user_timeline(page=pg, count=200)) if len(rs) == 0: break stash_tweets(service, username, rs) pg += 1 ## 3. our own retweets (stupid api - not included in above) pg = 1 Verbose = True while True: rs = retryOnError("own_retweets %d" % (pg,), lambda: t.statuses.retweeted_by_me(page=pg, count=200)) if len(rs) == 0: break stash_tweets(service, username, rs) pg += 1 ## 4. direct messages we sent pg = 1 while True: rs = retryOnError("direct_messages_sent %d" % (pg,), lambda: t.direct_messages.sent(page=pg, count=200)) if len(rs) == 0: break stash_tweets(service, username, rs) pg += 1 ## 5. direct messages we received pg = 1 while True: rs = retryOnError("direct_messages_received %d" % (pg,), lambda: t.direct_messages(page=pg, count=200)) if len(rs) == 0: break stash_tweets(service, username, rs) pg += 1 ## 6. tweets from friends cr = -1 friends = [] while cr != 0: rs = retryOnError("get_friends cursor=%d" % cr, lambda: t.friends.ids(cursor=cr)) friends.extend(rs['ids']) cr = rs['next_cursor'] print >> sys.stderr, "friends:", friends for friend in friends: pg = 1 while True: rs = retryOnError( "friend_timeline %s %d" % (friend, pg), lambda: t.statuses.user_timeline(id=friend, page=pg, count=200)) if len(rs) == 0: break stash_tweets(service, username, rs) pg += 1 print >> sys.stderr, "friend: %s done" % friend
def usage(): print "Usage: %s [-c <config>]" % sys.argv[0] sys.exit(2) def main(): try: opts, args = getopt.getopt( sys.argv[1:], "hsc:", ["help", "secure", "config="]) except getopt.GetoptError, err: print str(err) usage() configfile = "perscon.conf" https = False for o, a in opts: if o in ("-c", "--config"): configfile = a elif o in ("-s", "--secure"): https = True elif o in ("-h", "--help"): usage() else: usage() config.parse(configfile) db.open() port = config.port() print "Listening on port %d" % port if https: server = SecureHTTPServer(('', port), PersconHandler) else: server = HTTPServer(('', port), PersconHandler) server.serve_forever() if __name__ == '__main__': main()