def main(config_path): cfg = conf.Config(config_path) print(cfg.config_file_path) cfg.update_config() test_cfg = conf.Config() # cfg.init_all_timestamp() start(cfg)
def main(): config = conf.Config() username = config.params.get('icloud', {}).get('username', None) password = config.params.get('icloud', {}).get('password', None) api = PyiCloudService(username, password) if api.requires_2fa: print ("Two-step authentisation required. Your trusted devices are:") devices = api.trusted_devices for i, device in enumerate(devices): print (" %s: %s" % (i, device.get('deviceName', "SMS to %s" % device.get('phoneNumber')))) device = click.prompt('Which device would you like to use?', default=0) device = devices[device] if not api.send_verification_code(device): print ("Failed to send verification code") sys.exit(1) code = click.prompt('Please enter validation code') if not api.validate_verification_code(device, code): print ("Failed to verify verification code") sys.exit(1)
def initLogging(cls, c=None): if c: cls.cf = c if cls.cf.loglevel > 5: cls.cf.loglevel = 5 else: cls.cf = conf.Config()
def calendar(): config = conf.Config() username = config.params.get('icloud', {}).get('username', None) password = config.params.get('icloud', {}).get('password', None) icloud_api = PyiCloudService(username, password) if icloud_api.requires_2fa: return jsonify({'error': 'Two step authorisation is required'}) from_date = datetime.today() end_date = from_date + timedelta(days=14) events = icloud_api.calendar.events(from_date, end_date) results = [] for event in events: title = event['title'] start_date = event['startDate'] end_date = event['endDate'] start_date_object = datetime(start_date[1], start_date[2], start_date[3], start_date[4], start_date[5]) end_date_object = datetime(end_date[1], end_date[2], end_date[3], end_date[4], end_date[5]) start_date_object = start_date_object + timedelta(hours=1) date_formatted = start_date_object.strftime('%a, %d %b') date_str = start_date_object.strftime('%Y%m%d') event_item = { 'title': title, 'start': None if start_date[4] == 0 and start_date[5] == 0 else start_date_object.strftime('%H:%M'), 'end': None if end_date[4] == 0 and end_date[5] == 0 else end_date_object.strftime('%H:%M') } date_item = { 'date': date_str, 'date_formatted': date_formatted, 'events': [event_item] } date_index = next( (index for (index, d) in enumerate(results) if d["date"] == date_str), None) if date_index: results[date_index]['events'].append(event_item) else: results.append(date_item) return jsonify({'days': sorted(results, key=lambda k: k['date'])})
def calc_icon(week, day): """Calculate the icon for how the notification""" week_hours = delta_hours(week) day_hours = delta_hours(day) config = conf.Config() if ((week_hours >= (config.warnlimit * 5)) or (day_hours >= config.warnlimit)): return "dialog-warning" if ((week_hours >= (config.infolimit * 5)) or (day_hours >= config.infolimit)): return "dialog-information" return None
def upload_video(video_name): config = conf.Config() access_token = config.params.get('dropbox', {}).get('access_token', None) app_folder = config.params.get('dropbox', {}).get('app_folder', None) dbx = dropbox.Dropbox(access_token) with open("static/{}".format(video_name), "rb") as imageFile: f = imageFile.read() dbx.files_upload( f, '/{app_folder}/{filename}.mp4'.format( app_folder=app_folder, filename=datetime.now().strftime('%s'))) return jsonify({'status': 'done'})
def distance(origin, destination): config = conf.Config() api_key = config.params.get('google_map', {}).get('api_key', None) url = 'https://maps.googleapis.com/maps/api/distancematrix/json?' \ 'origins={origin}&destinations={destination}&key={key}'.format( key = api_key, origin = origin, destination = destination ) response = requests.get(url=url).json() return jsonify( {'duration': response['rows'][0]['elements'][0]['duration']['text']})
def news_feed(news_channel): config = conf.Config() feed_url = config.params.get('news_feed', {}).get(news_channel, None) if not feed_url: return jsonify( {'error': 'feed url is not specified in the config file.'}) feed = feedparser.parse(feed_url) results = [] for entry in feed.entries: results.append({ 'title': entry.title, 'description': entry.description }) return jsonify({ 'news': results, })
def main(config_path): cfg = conf.Config(config_path) cfg.update_config() start(cfg)
import webapp2 import libsna, conf, fbutils, sessionmanager from google.appengine.ext import db import networkx as nx conf = conf.Config() def sorted_map(inmap): return sorted(inmap.iteritems(), key=lambda (k, v): (-v, k)) def computeLeague(libSNA, session): d = nx.degree(libSNA.graph) c = nx.closeness_centrality(libSNA.graph) b = nx.betweenness_centrality(libSNA.graph) ds = sorted_map(d) cs = sorted_map(c) bs = sorted_map(b) weights = [.50, .30, .20] names1 = [x[0] for x in ds[:10]] names2 = [x[0] for x in cs[:10]] names3 = [x[0] for x in bs[:10]] names = list(set(names1) | set(names2) | set(names3)) names = sorted(names, key=lambda name: (float(d[name]) / ds[0][1]) * weights[0] +
self.connect.commit() return True except MySQLdb.Error as e: if e.args[0] == 1062: # 忽略数据库中重复的的项目 logging.info("existed in database %s" % query) return True except Exception as e: logging.exception( "update database exception % s, error: %s" % (query, e)) self.connect_database() return False if __name__ == "__main__": log.init_log() config = conf.Config() print config.__dict__ entity_connector = DatabaseConnector( config=config, db_host=config.entity_db_host, db_port=config.entity_db_port, db_name="twitter", db_table_name="", db_charset=config.entity_db_charset, db_user=config.entity_db_user, db_pass_word=config.entity_db_pass_word) entity_connector.connect_database() print entity_connector.get_ontime_articles()
from flask import Flask import conf import resource_manager import score app = Flask(__name__) cfg = conf.Config("./conf/config.json") rmq = resource_manager.RMQueue() @app.route('/') def api_root(): return 'Welcome, this is hadoop yarn scoring and predicting system.' @app.route('/update/app') def update_app(): score.update_app_info(rmq, cfg) return 'You are updating job info' @app.route('/update/cluster') def update_cluster(): score.update_cluster_info(rmq, cfg) return 'You are updating cluster info' @app.route('/update/scheduler') def update_scheduler(): score.update_scheduler_info(rmq, cfg)
def _set_catch(self, namespace, catch, source_type): self._catch_lock.acquire() self._cache[namespace] = conf.Config(catch, source_type) self._catch_lock.release()
port = conf.get("%s.db_port" % prefix) user = conf.get("%s.db_user" % prefix) pwd = conf.get("%s.db_pwd" % prefix) dbName = conf.get("%s.db_name" % prefix) return host, port, user, pwd, dbName if __name__ == "__main__": db = Mysqldb('db') data = db.select("select * from shopping_trade_info limit 10") id = data[0]["trans_id"] print id exit(1) conf = conf.Config("db.conf") host = conf.get("db_test.db_host") port = conf.get("db_test.db_port") user = conf.get("db_test.db_user") pwd = conf.get("db_test.db_pwd") dbName = conf.get("db_test.db_name") db = Mysqldb(host, port, user, pwd, dbName) data = db.select("select * from shopping_trade_info limit 10") id = data[0]["trans_id"] print id data = db.select("select *from shopping_trade_info where trans_id='%s'" % id) print data
def weather(location_name): config = conf.Config() locations = config.params.get('weather', {}).get('locations', []) if not locations: return jsonify( {'error': 'locations are not defined in the config file.'}) for location in locations: if location.get('name', None) == location_name: break else: location = None if not location: return jsonify({ 'error': 'location {} is not defined in the config file.'.format( location_name) }) key = config.params.get('weather', {}).get('key', None) long = location.get('long', None) lat = location.get('lat', None) if all([key, long, lat]): url = 'https://api.darksky.net/forecast/{key}/{long},{lat}?units=uk2'.format( key=key, long=long, lat=lat) response = requests.get(url=url).json() else: return jsonify({ 'error': 'key, long and lat should be defined in the config file.' }) daily = [{ 'icon': daily_data['icon'], 'day': datetime.fromtimestamp(daily_data['time']).strftime('%A'), 'temperature_high': int(round(daily_data['temperatureHigh'])), 'temperature_low': int(round(daily_data['temperatureLow'])), 'humidity': daily_data['humidity'], 'wind_speed': int(round(daily_data['windSpeed'])), 'summary': daily_data['summary'] } for daily_data in response['daily']['data']] hourly = [{ 'icon': hourly_data['icon'], 'day': datetime.fromtimestamp(hourly_data['time']).strftime('%A'), 'time': datetime.fromtimestamp(hourly_data['time']).strftime('%H:%M'), 'temperature': int(round(hourly_data['temperature'])), 'humidity': hourly_data['humidity'], 'wind_speed': int(round(hourly_data['windSpeed'])), 'feels_like': int(round(hourly_data['apparentTemperature'])) } for hourly_data in response['hourly']['data']] current = { 'temperature': int(round(response['currently']['temperature'])), 'feels_like': int(round(response['currently']['apparentTemperature'])), 'wind_speed': int(round(response['currently']['windSpeed'])), 'icon': response['currently']['icon'], 'humidity': response['currently']['humidity'], 'precip_type': response['currently'].get('precipType', None), 'precip_prob': int(round(100 * response['currently'].get('precipProbability', 0))), 'summary': response['currently']['summary'] } alerts = [{ 'title': alert['title'], 'severity': alert['severity'] } for alert in response.get('alerts', [])] return jsonify({ 'current': current, 'daily': daily, 'alerts': alerts, 'hourly': hourly })
mLdapConfig = None @classmethod def initLdap(cls, c = None): if c: cls.cf = c Log.logMsg(5, "Creating ldap context") ldapUrl = "ldapi:///" bindDN = "cn=config" try: cls.mLdapConfig = GenericLdapConfig(ldapUrl, cls.cf.ldap_starttls_required, bindDN, cls.cf.ldap_root_password) except Exception, e: Log.logMsg(1, "LDAP CONFIG FAILURE (%s)" % e) else: cls.cf = conf.Config() @classmethod def modify_attribute(cls, key, value): if cls.cf.ldap_is_master: atbase = "cn=accesslog" atfilter = "(objectClass=*)" atreturn = ['1.1'] zfilter = ZLdapFilterFactory.getInstance().fromFilterString(FilterId.ZMCONFIGD, atfilter) searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_BASE, ZSearchControls.SIZE_UNLIMITED, atreturn) mLdapContext = LdapClient.getContext(cls.mLdapConfig, LdapUsage.SEARCH) try: ne = mLdapContext.searchDir(atbase, zfilter, searchControls) except: cls.master = False else:
def main(config_path): cfg = conf.Config(config_path) start(cfg)
from flask import Flask, url_for import conf import resource_manager import score app = Flask(__name__) #rmq = None #cfg = None cfg = conf.Config() # SINGLETON rmq = resource_manager.RMQueue() # SINGLETON @app.route('/') def api_root(): return 'Welcome, this is hadoop yarn scoring and predicting system.' @app.route('/update/app') def update_app(): score.update_app_info(rmq, cfg) return 'You are updating job info' @app.route('/update/cluster') def update_cluster(): score.update_cluster_info(rmq, cfg) return 'You are updating cluster info' @app.route('/update/scheduler') def update_scheduler(): score.update_scheduler_info(rmq, cfg) return 'You are updating scheduler info'
parser.add_option("-i", "--immed", dest="immed_start", action="store_true", help="Start user code immediately.") parser.add_option("-l", "--log-dir", dest="log_dir", default="./", help="Log into the given directory.") args, trailing_args = parser.parse_args() return args if __name__ == "__main__": args = parse_args() config = conf.Config(prog_dir=os.path.abspath(os.path.dirname(__file__)), log_dir=args.log_dir) log.init(config.log_fname, config.log_dir, debug=args.debug) runner = RobotRunner(config, debug=args.debug) if not args.immed_start: "Wait for the button press to happen" call("pyenv_start") runner.run()
def __init__(self): self.tree = Tree() self.MAX_METRIC_COUNT = 12 self.CAL_INTERVAL_IN_SECOND = 2 * 60 * 60 self.conf = conf.Config("./conf/config.json")
from flask import Flask, render_template, request, redirect, url_for import oauth import conf import recommendation import api import hashlib import math import re import base64 from io import BytesIO from PIL import Image from flaskext.markdown import Markdown app = Flask(__name__) app.config.from_object(conf.Config()) with app.app_context(): sp_oauth = oauth.SpotifyOAuth() rec = None md = Markdown(app) @app.route('/') def main(): global rec rec = recommendation.Recommendation() return render_template('index.html') @app.route('/spotirec') def spotirec(): return render_template('spotirec.html')