Ejemplo n.º 1
0
def init():
    """Reads the config file"""
    try:
        # Try to open the config file and parse it
        parser = configparser.RawConfigParser()
        parser.read('ghdata.cfg')
        host = parser.get('Database', 'host')
        port = parser.get('Database', 'port')
        user = parser.get('Database', 'user')
        password = parser.get('Database', 'pass')
        db = parser.get('Database', 'name')
        global client
        client = GHDataClient(db_host=host,
                              db_port=port,
                              db_user=user,
                              db_pass=password,
                              db_name=db)
        app.run()
    except:
        # Uh-oh. Save a new config file.
        print('Failed to open config file.')
        config = configparser.RawConfigParser()
        config.add_section('Database')
        config.set('Database', 'host', '127.0.0.1')
        config.set('Database', 'port', '3306')
        config.set('Database', 'user', 'root')
        config.set('Database', 'pass', 'root')
        config.set('Database', 'name', 'ghtorrent')
        # Writing our configuration file to 'example.cfg'
        with open('ghdata.cfg', 'w') as configfile:
            config.write(configfile)
        print('Default config saved to ghdata.cfg')
    def __init__(self, args):
        parser = ConfigParser()
        parser.read([args.config_file])

        self.host = parser.get("Database", "HostName")
        self.dbname = parser.get("Database", "DatabaseName")
        self.user = parser.get("Database", "UserName")
        self.password = parser.get("Database", "Password")

        self.site_id = args.site_id

        if args.season_start:
            self.season_start = parse_date(args.season_start)
        else:
            self.season_start = parse_date('2015-01-01')

        if args.season_end:
            self.season_end = parse_date(args.season_end)
        else:
            self.season_end = parse_date('2050-12-31')

        if args.cp_rm:
            self.cp_rm = get_bool_value(args.cp_rm)
        else:
            self.cp_rm = False

        if args.verify_only:
            self.verify_only = get_bool_value(args.verify_only)
        else:
            self.verify_only = True
Ejemplo n.º 3
0
    def __init__(self, args):
        parser = ConfigParser()
        parser.read([args.s4c_config_file])

        self.host = parser.get("Database", "HostName")
        self.dbname = parser.get("Database", "DatabaseName")
        self.user = parser.get("Database", "UserName")
        self.password = parser.get("Database", "Password")

        self.site_id = args.site_id
        self.config_file = args.config_file
        self.input_shape_file = args.input_shape_file
        self.output_data_dir = args.output_data_dir
        self.new_acq_date = args.new_acq_date
        self.older_acq_date = args.older_acq_date
        # self.orbit_list_file = args.orbit_list_file
        self.seg_parcel_id_attribute = args.seg_parcel_id_attribute
        self.output_shapefile = args.output_shapefile
        self.do_cmpl = args.do_cmpl
        self.test = args.test

        self.input_products_list = None
        if args.input_products_list:
            self.input_products_list = args.input_products_list

        self.prds_are_tif = int(args.prds_are_tif)

        if args.season_start:
            self.season_start = parse_date(args.season_start)
            print("Season_start = ", args.season_start)

        if args.season_end:
            self.season_end = parse_date(args.season_end)
            print("Season_end = ", args.season_end)
def buffer_post(profile, content, url):
    parser = ConfigParser()
    parser.read("whconfig.ini")

    client_id = parser.get('BUFFER', 'client_id')
    buffer_access = parser.get('BUFFER', 'access')
    buffer_profile = parser.get('BUFFER', profile)

    client = BackendApplicationClient(client_id=client_id)
    oauth = OAuth2Session(token=buffer_access, client=client)
    auth_code = oauth.token
    if profile == 'twitter':
        requests.post(
            "https://api.bufferapp.com/1/updates/create.json?access_token=" +
            auth_code,
            data={
                'profile_ids': buffer_profile,
                'text': content + ' ' + url,
                'now': 1
            })
    if profile == 'facebook':
        requests.post(
            "https://api.bufferapp.com/1/updates/create.json?access_token=" +
            auth_code,
            data={
                'profile_ids': buffer_profile,
                'text': content + ' ' + url,
                'link': url,
                'now': 1
            })
Ejemplo n.º 5
0
def config(section='postgresql', filename='database.ini'):
    parser = ConfigParser()
    parser.read(filename)

    arguments = {}
    if parser.has_section(section):
        params = parser.items(section)
        for param in params:
            arguments[param[0]] = param[1]
    else:
        raise Exception(f'Section {section} not found in the {filename} file')
    return arguments
Ejemplo n.º 6
0
def load_config():
    try:
        parser = SafeConfigParser()
        parser.read('config.ini')
        items = parser.items('pindown')
        config = {}
        for item in items:
            config[item[0]] = item[1]
        log.debug("Config loaded")
        return config
    except Exception as e:
        log.error(e.message)
        return False
Ejemplo n.º 7
0
def parse_config(filename):
    """
    Parse input file into config dictionary. For each section in the input file it will create a key
    with the value being a dictionary of key value pairs of options from that section.
    """
    if not os.path.exists(filename):
        raise ConfigError('Config file does not exist.')
    parser = ConfigParser.RawConfigParser()
    parser.read(filename)
    cfg = {}
    for section in parser.sections():
        cfg[section] = dict(parser.items(section))
    return cfg
Ejemplo n.º 8
0
def init():
    '''
    method to parse global conf

    return Configdictionary
    '''
    confname = os.path.join(os.getcwd(), '..', 'global.conf')

    cDict = {}
    parser = SafeConfigParser()
    parser.read(confname)
    for section_name in parser.sections():
        for name, value in parser.items(section_name):
            cDict[name] = value

    logger.info('\033[31m Global Configuration %s \033[0m \n' % (cDict))
    return cDict
Ejemplo n.º 9
0
def retrieve_schedule():
    """Search the schedules directory for an appropriate schedule"""

    # Try several possible sources for the schedule with increasing generality
    root = os.path.dirname(os.path.abspath(__file__))
    sources_to_try = [config.defaults_dict["current_exhibit"], "default"]
    today_filename = datetime.datetime.now().date().isoformat(
    ) + ".ini"  # eg. 2021-04-14.ini
    today_day_filename = datetime.datetime.now().strftime(
        "%A").lower() + ".ini"  # eg. monday.ini
    schedule_to_read = None

    for source in sources_to_try:
        sched_path = os.path.join(root, "schedules", source)
        try:
            schedules = os.listdir(sched_path)
            if today_filename in schedules:
                print("Found schedule", today_filename, "in", source)
                schedule_to_read = os.path.join(sched_path, today_filename)
                break
            if today_day_filename in schedules:
                print("Found schedule", today_day_filename, "in", source)
                schedule_to_read = os.path.join(sched_path, today_day_filename)
                break
            if "default.ini" in schedules:
                print("Found schedule default.ini in", source)
                schedule_to_read = os.path.join(sched_path, "default.ini")
                break
        except FileNotFoundError:
            pass

    if schedule_to_read is not None:
        parser = configparser.ConfigParser(delimiters=("="))
        parser.read(schedule_to_read)
        if "SCHEDULE" in parser:
            readSchedule(parser["SCHEDULE"])
        else:
            print("retrieve_schedule: error: no INI section 'SCHEDULE' found!")
    else:
        # Check again tomorrow
        config.schedule = []
        config.schedule.append((datetime.time(0, 1), "reload_schedule"))
        print("No schedule for today. Checking again tomorrow...")
Ejemplo n.º 10
0
def parse_config():
    """Function to parse the config file for PETRARCH."""
    config_file = glob.glob('config.ini')
    parser = ConfigParser()
    print os.path.dirname(sys.executable)
    if config_file:
        print 'Found a config file in working directory.'
        parser.read(config_file)
        try:
            cwd = os.getcwd()
            actors_file = parser.get('Dictionary Files', 'actors')
            verbs_file = parser.get('Dictionary Files', 'verbs')
            actors_file = os.path.join(cwd, 'dictionaries', actors_file)
            verbs_file = os.path.join(cwd, 'dictionaries', verbs_file)
            direct = parser.get('StanfordNLP', 'stanford_dir')
            stanfordnlp = os.path.expanduser(direct)
            return actors_file, verbs_file, stanfordnlp
        except Exception, e:
            print 'Problem parsing config file. {}'.format(e)
Ejemplo n.º 11
0
def get_config(configuration=None):
    """ Returns a json file containing the configuration to use in the app

    The configuration to be used can be passed as a parameter, 
    otherwise the one indicated by default in config.ini is chosen

    ------------------------------------
    [CONFIG]
    CONFIG = The_default_configuration
    ------------------------------------

    Params:
        - configuration: if it is a string it indicates the configuration to choose in config.ini
    """
    try:
        parser = configparser.ConfigParser()
        if parser.read('config.ini') != []:

            if type(configuration
                    ) != str:  # if it's not a string, take the default one
                configuration = parser["CONFIG"]["CONFIG"]

            logging.info("- GoOutSafe:Bookings CONFIGURATION: %s",
                         configuration)
            configuration = parser._sections[
                configuration]  # get the configuration data

            parsed_configuration = {}
            for k, v in configuration.items(
            ):  # Capitalize keys and translate strings (when possible) to their relative number or boolean
                k = k.upper()
                parsed_configuration[k] = v
                try:
                    parsed_configuration[k] = int(v)
                except:
                    try:
                        parsed_configuration[k] = float(v)
                    except:
                        if v == "true":
                            parsed_configuration[k] = True
                        elif v == "false":
                            parsed_configuration[k] = False

            for k, v in DEFAULT_CONFIGURATION.items():
                if not k in parsed_configuration:  # if some data are missing enter the default ones
                    parsed_configuration[k] = v

            return parsed_configuration
        else:
            return DEFAULT_CONFIGURATION
    except Exception as e:
        logging.info("- GoOutSafe:Bookings CONFIGURATION ERROR: %s", e)
        logging.info("- GoOutSafe:Bookings RUNNING: Default Configuration")
        return DEFAULT_CONFIGURATION
def buffer_post(profile, content, url):
    parser = ConfigParser()
    parser.read("whconfig.ini")
    print('begin!!')
    client_id = parser.get('BUFFER', 'client_id')
    buffer_access = parser.get('BUFFER', 'access')
    buffer_profile = parser.get('BUFFER', profile)

    client = BackendApplicationClient(client_id=client_id)
    oauth = OAuth2Session(token=buffer_access, client=client)
    auth_code = oauth.token
    nm_archive = 0

    if profile == 'Twitter':
        if nm_archive == 1:
            requests.post(
                "https://api.bufferapp.com/1/updates/create.json?access_token="
                + auth_code,
                data={
                    'profile_ids': buffer_profile,
                    'text': 'From the archive: ' + content + ' ' + url
                })
        if nm_archive == 0:
            requests.post(
                "https://api.bufferapp.com/1/updates/create.json?access_token="
                + auth_code,
                data={
                    'profile_ids': buffer_profile,
                    'text': content + ' ' + url
                })

    if profile == 'Facebook':
        requests.post(
            "https://api.bufferapp.com/1/updates/create.json?access_token=" +
            auth_code,
            data={
                'profile_ids': buffer_profile,
                'text': content + ' ' + url,
                'link': url
            })
Ejemplo n.º 13
0
def auth():
    parser = ConfigParser.ConfigParser()
    parser.read('config.ini')
    
    OAUTH_TOKEN = parser.get('twitter', 'OAUTH_TOKEN') 
    OAUTH_SECRET = parser.get('twitter', 'OAUTH_SECRET')
    CONSUMER_KEY = parser.get('twitter', 'CONSUMER_KEY')
    CONSUMER_SECRET = parser.get('twitter', 'CONSUMER_SECRET')
    print "[+] Authenticating..."
    try:
        t = Twitter(
                    auth=OAuth(
                               OAUTH_TOKEN, 
                               OAUTH_SECRET, 
                               CONSUMER_KEY, 
                               CONSUMER_SECRET
                              )
                   )
        print "[+] Authentication Succesful!"
        return t
    except Exception, e:
        print "[!] Error authentcating: ", e
        exit()
from ConfigParser import SafeConfigParser
import simplejson

"""
	ARGVS:
	1 - "repos.csv"

	NEED:
	- github_account.conf
"""

ORG_NAME = 'usc-csci104-spring2015'
CSV_FILENAME = sys.argv[1]

parser = SafeConfigParser()
parser.read("github_account.conf")
githubUsername = parser.get("github", "username")
githubPassword = parser.get("github", "password")

def hint(text, color='34'):
	return '\t\033[{}m{}\033[0m'.format(color, text)

def githubPost(url, payload):
	""" Send a POST request to GitHub via API """
	r = requests.post(url, data=simplejson.dumps(payload), auth=(githubUsername, githubPassword))
	res = simplejson.loads(r.content)
	if r.status_code == 201 or r.status_code == 200:
		return res
	else:
		details = ""
		if "errors" in res:
Ejemplo n.º 15
0
def init():
    """Reads the config file"""
    try:
        # Try to open the config file and parse it
        parser = configparser.RawConfigParser()
        parser.read('ghdata.cfg')
        host = parser.get('Database', 'host')
        port = parser.get('Database', 'port')
        user = parser.get('Database', 'user')
        password = parser.get('Database', 'pass')
        db = parser.get('Database', 'name')
        public_www_api_key = parser.get('PublicWWW', 'APIKey')
        debug = parser.get('Development', 'developer')
        try:
            global client
            client = GHDataClient(db_host=host,
                                  db_port=port,
                                  db_user=user,
                                  db_pass=password,
                                  db_name=db,
                                  public_www_api_key=public_www_api_key,
                                  debug=debug)
        except:
            print('Couldn\'t start. Double check ghdata.cfg for errors.')

    except:
        # Uh-oh. Save a new config file.
        print('Failed to open config file.')
        config = configparser.RawConfigParser()
        config.add_section('Database')
        config.set('Database', 'host', '127.0.0.1')
        config.set('Database', 'port', '3306')
        config.set('Database', 'user', 'root')
        config.set('Database', 'pass', 'root')
        config.set('Database', 'name', 'ghtorrent')
        config.add_section('PublicWWW')
        config.set('PublicWWW', 'APIKey', '0')
        config.add_section('Development')
        config.set('Development', 'developer', '0')
        # Writing our configuration file to 'example.cfg'
        with open('ghdata.cfg', 'w') as configfile:
            config.write(configfile)
        print('Default config saved to ghdata.cfg')
        sys.exit()

    if (client.DEBUG):
        # Serve the front-end files in debug mode to make it easier for developers to work on the interface
        # @todo: Figure out why this isn't working.
        @app.route('/')
        def root():
            return app.send_static_file('frontend/index.html')

        @app.route('/scripts/<path>')
        def send_scripts(path):
            return send_from_directory('frontend/scripts', path)

        @app.route('/styles/<path>')
        def send_styles(path):
            return send_from_directory('frontend/styles', path)

        app.debug = True

    app.run(debug=client.DEBUG)
Ejemplo n.º 16
0
 def _parse_config(self, config_file_path):
     parser = ConfigParser.ConfigParser()
     parser.read(config_file_path)
     options = parser.options('Options')
     for option in options:
         self.__dict__[option] = parser.get('Options', option)
Ejemplo n.º 17
0
        parser.read(config_file)
        try:
            cwd = os.getcwd()
            actors_file = parser.get('Dictionary Files', 'actors')
            verbs_file = parser.get('Dictionary Files', 'verbs')
            actors_file = os.path.join(cwd, 'dictionaries', actors_file)
            verbs_file = os.path.join(cwd, 'dictionaries', verbs_file)
            direct = parser.get('StanfordNLP', 'stanford_dir')
            stanfordnlp = os.path.expanduser(direct)
            return actors_file, verbs_file, stanfordnlp
        except Exception, e:
            print 'Problem parsing config file. {}'.format(e)
    else:
        cwd = os.path.abspath(os.path.dirname(__file__))
        config_file = os.path.join(cwd, 'default_config.ini')
        parser.read(config_file)
        print 'No config found. Using default.'
        try:
            actors_file = parser.get('Dictionary Files', 'actors')
            verbs_file = parser.get('Dictionary Files', 'verbs')
            actors_file = os.path.join(cwd, 'dictionaries', actors_file)
            verbs_file = os.path.join(cwd, 'dictionaries', verbs_file)
            direct = parser.get('StanfordNLP', 'stanford_dir')
            stanfordnlp = os.path.expanduser(direct)
            return actors_file, verbs_file, stanfordnlp
        except Exception, e:
            print 'Problem parsing config file. {}'.format(e)


def main():
    """Main function"""
Ejemplo n.º 18
0
        return Response(response=serialize(func, owner=owner, repo=repo),
                        status=200,
                        mimetype="application/json")

    generated_function.__name__ = func.__name__
    return generated_function


app = Flask(__name__, static_url_path=os.path.abspath('static/'))
CORS(app)
# Flags and Initialization
"""Reads the config file"""
try:
    # Try to open the config file and parse it
    parser = configparser.RawConfigParser()
    parser.read('ghdata.cfg')
    host = parser.get('Server', 'host')
    port = parser.get('Server', 'port')
    try:
        dbstr = 'mysql+pymysql://{}:{}@{}:{}/{}'.format(
            parser.get('Database', 'user'), parser.get('Database', 'pass'),
            parser.get('Database', 'host'), parser.get('Database', 'port'),
            parser.get('Database', 'name'))
        ghtorrent = ghdata.GHTorrent(dbstr=dbstr)
    except Exception as e:
        print("Failed to connect to database (" + str(e) + ")")
    publicwww = ghdata.PublicWWW(
        public_www_api_key=parser.get('PublicWWW', 'APIKey'))
    if (parser.get('Development', 'developer') == '1'
            or os.getenv('FLASK_DEBUG') == '1'):
        DEBUG = True
Ejemplo n.º 19
0
			listbyjob[y][x2] = entrylist[x][y]

	# If there are any projects with time in the entry list
	# this function simply creates a list of the job numbers
	if len(entrylist.keys())>0:
		jobslist = sorted(list(set(reduce(lambda x,y:x+y,[entrylist[x].keys() for x in sorted(entrylist.keys())]))))
	else:
		jobslist = {}
		errorlist.append("Warning: No time entries found")

	return json.dumps({'jobs' : jobslist, 'entries' : entrylist, 'errors' : errorlist, 'listbyjob': listbyjob }, sort_keys=True, indent=4)
	#print json.dumps(entrylist)

if __name__ == "__main__":
	parser = SafeConfigParser()
	parser.read('simple.ini')

	try:
		weekending = dateutil.parser.parse(sys.argv[1])
	except:
		weekending = datetime.datetime.now()

	try:
		apikey = sys.argv[2]
	except:
		try:
			apikey = parser.get('toggl','apikey')
		except:
			print "Failed"
			exit()
Ejemplo n.º 20
0
 def __init_config(self, blog, config):
     parser = ConfigParser()
     parser.read(config)
     if not parser.has_section(blog):
         raise Exception('blog "%s" not in config "%s"' % (blog, config))
     self.__cfg = dict(parser.items(blog))
import json
from ConfigParser import SafeConfigParser
from simple_salesforce import Salesforce
import openpyxl
from openpyxl.styles import PatternFill, Border, Side, Font
import dateutil.parser
from pytz import timezone
import pytz
from datetime import datetime, timedelta

### Personal Credentials
parser = SafeConfigParser()
parser.read('salesforce.conf')
sf_url = parser.get('SalesForce', 'url')
sf_usr = parser.get('SalesForce', 'username')
sf_pwd = parser.get('SalesForce', 'password')
sf_tkn = parser.get('SalesForce', 'token')
sf_account = parser.get('SalesForce', 'account')
sf_cloud = parser.get('SalesForce', 'cloud')
last_time = parser.get('SalesForce', 'last_time')
now = parser.get('SalesForce', 'now')
tz = parser.get('SalesForce', 'tz')
duration = int(parser.get('SalesForce', 'duration'))
report_file_name = parser.get('SalesForce', 'report_file_name')

### L1 Variables
font_size = 10
default_font = Font(name="Open Sans", size=font_size)
defautl_font_hyperlink = Font(name="Open Sans",
                              size=font_size,
                              underline="single",
            content = 'From the archive: ' + content
        elif post_type == 'Archive' and len(tweet_text) > 102:
            content = 'From the archive: ' + social_queue[n][0]

        buffer_post(platform, content, page_url)

        n = +1


def main_proc():
    generate_media_queue()
    daily_loads()


global cursor

parser = ConfigParser()
parser.read("whconfig.ini")

wh_host = parser.get('MYSQL', 'host')
wh_user = parser.get('MYSQL', 'user')
wh_pass = parser.get('MYSQL', 'password')

conn = mysql.connect(host=wh_host,
                     user=wh_user,
                     password=wh_pass,
                     database='NovaraWH')

cursor = conn.cursor()

main_proc()
Ejemplo n.º 23
0
from configparser import ConfigParser
import urllib.request
import dateutil.parser
import json
import os
from timezonefinder import TimezoneFinder
from datetime import datetime, timedelta
import pytz
import csv
import xml.etree.ElementTree as ET
import sqlite3

parser = ConfigParser()
parser.read('../slowburn.config', encoding='utf-8')
darksky_key = parser.get('darksky', 'key')

gps_logs_directory = '../gps_logs/'

tf = TimezoneFinder()


def write_runs_to_csv(logs_directory):
    """Writes basic activity data from all GPS files in directory to a .csv file"""

    all_gps_files = os.listdir(logs_directory)

    with open('running.csv', 'w') as csv_file:
        file_writer = csv.writer(csv_file, delimiter=',',
                                 quotechar='|', quoting=csv.QUOTE_MINIMAL)

        file_writer.writerow(