예제 #1
0
    def __init__(self):
        self.host = config.get_host()
        self.port = config.get_port()
        self.username = config.get_username()
        self.password = config.get_password(self.host, self.port, self.username)
        self.remember = True

        if all((self.host, self.port, self.username, self.password)):
            if connect(self.host, self.port, self.username, self.password):
                sys.exit()

        self.construct()

        if self.host is not None:
            self.host_entry.set_text(self.host)

        if self.port is not None:
            self.port_entry.set_text(str(self.port))

        if self.username is not None:
            self.username_entry.set_text(self.username)

        if self.password is not None:
            self.password_entry.set_text(self.password)

        self.remember_checkbox.set_active(self.remember)
예제 #2
0
def create_connection():
    cluster = MongoClient('mongodb+srv://' + get_username() + ':' +
                          get_password() + '@cluster0.mfsww.mongodb.net/' +
                          get_db_name() + '?retryWrites=true&w=majority')
    db = cluster.CleanData
    col = db.tradeCandlesticks
    return col
예제 #3
0
def nav_login_page(driver):
    """
    :param driver: selenium driver already setup and set to Sporcle website

    Procedure navagates home sporcle page and logs in using the login javascript
    frame. Should end on home page and logged in.
    """
    #get login information from config class
    user_email = config.get_username()
    user_password = config.get_password()

    #HTML constants for element id/class names
    login_btn_id = "user-not-logged-in"
    username_c_name = "usernameInput"
    password_c_name = "passwordInput"
    submit_btn_c_name = "log-in-button"

    #click login button to open new frame to login
    driver.find_element_by_id(login_btn_id).click()

    #wait until login frame has loaded
    WebDriverWait(driver, 30).until(
        EC.presence_of_element_located((By.CLASS_NAME, username_c_name)))

    #enter login information and submit login
    driver.find_element_by_class_name(username_c_name).send_keys(user_email)
    driver.find_element_by_class_name(password_c_name).send_keys(user_password)
    submit = driver.find_element_by_class_name(submit_btn_c_name)

    #submits and loads new page
    timeout_catcher(driver=driver, func=submit.click)
예제 #4
0
def get_sp_api():
    username = config.get_username()
    token = util.prompt_for_user_token(
        username,
        _SP_SCOPE,
        client_id=config.get_sp_client_id(),
        client_secret=config.get_sp_client_secret(),
        redirect_uri=_SP_REDIRECT_URL)
    return spotipy.Spotify(auth=token)
예제 #5
0
def mega_upload_files(root, files, dest=None):
    mega = Mega()
    m = mega.login(config.get_username(), config.get_password())

    for filename in files:
        current = os.path.join(root, filename)
        print("Uploading: " + str(current))
        uploaded = m.upload(current)
        print(m.get_upload_link(uploaded))

        if dest != None:
            fileRef = m.find(filename)
            folder = m.find(dest)
            m.move(fileRef[0], folder)
예제 #6
0
from watson_developer_cloud import PersonalityInsightsV3
from flask import Flask, render_template, redirect, request
import config

# Flask初期設定
app = Flask(__name__)

# Twitter API 初期設定
CK = config.get_consumer_key()
CS = config.get_consumer_secret()
AT = config.get_access_token()
AS = config.get_access_secret()
twitter = Twitter(auth=OAuth(AT, AS, CK, CS))

# Watson Personality Insights API 初期設定
UN = config.get_username()
PS = config.get_password()
personality_insights = PersonalityInsightsV3(version='2017-10-13',
                                             username=UN,
                                             password=PS)

# json一時ファイル格納場所
json_folder = join(dirname(abspath('__file__')), 'tmp/')
if not exists(json_folder):
    mkdir(json_folder)


# jsonファイル名を返す
def get_file_name(type, user_name):
    if type == 'tw':
        return 'tweets-' + user_name + '.json'
예제 #7
0
def mega_file_listing(where=None):
    mega = Mega()
    m = mega.login(config.get_username(), config.get_password())
    files = m.get_files()

    """
    From http://julien-marchand.fr/blog/using-mega-api-with-python-examples:

    h: The ID of the node ;
    p: The ID of the parent node (directory) ;
    u: The owner of the node ;
    t: The type of the node:
        0: File
        1: Directory
        2: Special node: Root ("Cloud Drive")
        3: Special node: Inbox
        4: Special node: Trash Bin
    a: The attributes of the node. Currently only contains its name.
    k: The key of the node (used to encrypt its content and its attributes) ;
    s: The size of the node ;
    ts: The time of the last modification of the node.

    # Example of how the output of Mega looks like using https://github.com/richardasaurus/mega.py
    files = {
    u'fU8iHSqb': {u'a': {u'n': u'20130504-timelapse.mpg'}, u'h': u'fU8iHSqb', u'k': (89707223, 161142552, 573402337L, 1470622432L), u'ts': 1370116008, 'iv': (415650236, 706183423, 0, 0), u'p': u'OVV1jSKJ', u's': 2351010, 'meta_mac': (2158143175L, 4255881983L), u'u': u'BVs8yisX5G4', u't': 0, 'key': (496927595, 596465639, 2727332390L, 2852941855L, 415650236, 706183423, 2158143175L, 4255881983L)}, 
    u'Kc91ADhR': {u'a': {u'n': u'Fraggle'}, u'h': u'Kc91ADhR', u'k': (502465564, 1834626310, 1381829007, 76144220), u'ts': 1369248504, u'p': u'uBUzRayb', u'u': u'BVs8yisX5G4', u't': 1, 'key': (502465564, 1834626310, 1381829007, 76144220)}, 
    u'DB8QBbDY': {u'a': {'n': 'Rubbish Bin'}, u'h': u'DB8QBbDY', u'k': u'', u'ts': 1361396027, u'p': u'', u'u': u'BVs8yisX5G4', u't': 4}, 
    u'GYky1L7I': {u'a': {u'n': u'nop'}, u'h': u'GYky1L7I', u'k': (1062046627, 1804392549, 144264946, 7166313), u'ts': 1369248720, u'p': u'uBUzRayb', u'u': u'BVs8yisX5G4', u't': 1, 'key': (1062046627, 1804392549, 144264946, 7166313)}, 
    u'uA0WwDDC': {u'a': {u'n': u'FR1X09.avi'}, u'h': u'uA0WwDDC', u'k': (1419330019, 761322817, 2094550110L, 230172585L), u'ts': 1370113885, 'iv': (769934036, 1468969908, 0, 0), u'p': u'Kc91ADhR', u's': 266778624, 'meta_mac': (2710469947L, 2279034223L), u'u': u'BVs8yisX5G4', u't': 0, 'key': (2038235959, 2062446325, 3713413477L, 2322557638L, 769934036, 1468969908, 2710469947L, 2279034223L)}, 
    u'LZ0wkRiL': {u'a': {u'n': u'FR1X04.avi'}, u'h': u'LZ0wkRiL', u'k': (673266462, 1332906007, 1031887772L, 2010887260L), u'ts': 1369254134, 'iv': (1641340076, 154211803, 0, 0), u'p': u'Kc91ADhR', u's': 279056384, 'meta_mac': (4128886324L, 3650644366L), u'u': u'BVs8yisX5G4', u't': 0, 'key': (1240852402, 1178836428, 3415774632L, 2923683282L, 1641340076, 154211803, 4128886324L, 3650644366L)}, 
    u'uBUzRayb': {u'a': {'n': 'Cloud Drive'}, u'h': u'uBUzRayb', u'k': u'', u'ts': 1361396027, u'p': u'', u'u': u'BVs8yisX5G4', u't': 2}, 
    u'XQkWzCzD': {u'a': {u'n': u'FR1X03.avi'}, u'h': u'XQkWzCzD', u'k': (1822030122, 1461683990, 104100297, 171436116L), u'ts': 1369251984, 'iv': (739456022, 1878020475, 0, 0), u'p': u'Kc91ADhR', u's': 281018368, 'meta_mac': (172116505, 3745444068L), u'u': u'BVs8yisX5G4', u't': 0, 'key': (1082838332, 955242093, 209075152, 3574143152L, 739456022, 1878020475, 172116505, 3745444068L)}, 
    u'6ZtkhaQD': {u'a': {u'n': u'20130505-timelapse.mpg'}, u'h': u'6ZtkhaQD', u'k': (1828039708, 1316190495, 1207177820L, 407323452), u'ts': 1370116209, 'iv': (967685081, 75438788, 0, 0), u'p': u'OVV1jSKJ', u's': 9489254, 'meta_mac': (4200315324L, 1578827400), u'u': u'BVs8yisX5G4', u't': 0, 'key': (1431838661, 1242325979, 3182406624L, 1180548532, 967685081, 75438788, 4200315324L, 1578827400)}, 
    u'bMdEhZ5Q': {u'a': {'n': 'Inbox'}, u'h': u'bMdEhZ5Q', u'k': u'', u'ts': 1361396027, u'p': u'', u'u': u'BVs8yisX5G4', u't': 3}, 
    u'jVlyVIqb': {u'a': {u'n': u'FR1X05.avi'}, u'h': u'jVlyVIqb', u'k': (112256182, 218491874, 982809646, 1581866576), u'ts': 1369255313, 'iv': (1723776206, 1447320173, 0, 0), u'p': u'Kc91ADhR', u's': 281335808, 'meta_mac': (889945617, 2012844929), u'u': u'BVs8yisX5G4', u't': 0, 'key': (1611552888, 1531031951, 262079039, 699452881, 1723776206, 1447320173, 889945617, 2012844929)}, 
    u'nEtiSDbb': {u'a': {u'n': u'FR1X07.avi'}, u'h': u'nEtiSDbb', u'k': (225167755, 1671501548, 591928764, 63089283), u'ts': 1370111321, 'iv': (1300145638, 2013187368, 0, 0), u'p': u'Kc91ADhR', u's': 281380864, 'meta_mac': (979318925, 1617691340), u'u': u'BVs8yisX5G4', u't': 0, 'key': (1075145837, 341826500, 420947249, 1672390735, 1300145638, 2013187368, 979318925, 1617691340)}, 
    u'XA0CmS5R': {u'a': {u'n': u'FR1X06.avi'}, u'h': u'XA0CmS5R', u'k': (1811000465, 757679140, 1277418342L, 1150075587L), u'ts': 1370110241, 'iv': (1120378468, 1265751793, 0, 0), u'p': u'Kc91ADhR', u's': 281528320, 'meta_mac': (3583748394L, 3453581643L), u'u': u'BVs8yisX5G4', u't': 0, 'key': (691417845, 1717080789, 2579001932L, 2304097160L, 1120378468, 1265751793, 3583748394L, 3453581643L)}, 
    u'nNV3wb6L': {u'a': {u'n': u'FR1X08.avi'}, u'h': u'nNV3wb6L', u'k': (857321979, 113754691, 550525577L, 2005802334), u'ts': 1370112438, 'iv': (2091818972, 474711454, 0, 0), u'p': u'Kc91ADhR', u's': 280852480, 'meta_mac': (3944887044L, 997593366), u'u': u'BVs8yisX5G4', u't': 0, 'key': (1337404967, 445401053, 3421661581L, 1291324488, 2091818972, 474711454, 3944887044L, 997593366)}, 
    u'bRlQGKaa': {u'a': {u'n': u'FR1X02.avi'}, u'h': u'bRlQGKaa', u'k': (1834413953, 323343779, 1972206936L, 926199209), u'ts': 1369250867, 'iv': (1923007029, 226044668, 0, 0), u'p': u'Kc91ADhR', u's': 278165504, 'meta_mac': (3813458802L, 2051077149), u'u': u'BVs8yisX5G4', u't': 0, 'key': (533212596, 507314015, 2529279530L, 1299470772, 1923007029, 226044668, 3813458802L, 2051077149)}, 
    u'OIcyBYBI': {u'a': {u'n': u'20130506-timelapse.mpg'}, u'h': u'OIcyBYBI', u'k': (1803067817, 1556254904, 1135565474L, 1855076844), u'ts': 1370116238, 'iv': (7431726, 229302727, 0, 0), u'p': u'OVV1jSKJ', u's': 8058367, 'meta_mac': (2271367677L, 1318499050), u'u': u'BVs8yisX5G4', u't': 0, 'key': (1795803015, 1365799295, 3301772127L, 537168646, 7431726, 229302727, 2271367677L, 1318499050)}, 
    u'3FlxEKjb': {u'a': {u'n': u'FR1X01.avi'}, u'h': u'3FlxEKjb', u'k': (1928705133, 1361926709, 871495869L, 2008746031), u'ts': 1369249819, 'iv': (1906187233, 153356539, 0, 0), u'p': u'Kc91ADhR', u's': 283379712, 'meta_mac': (2759251385L, 2095529633), u'u': u'BVs8yisX5G4', u't': 0, 'key': (57388940, 1477006030, 2542218500L, 190592654, 1906187233, 153356539, 2759251385L, 2095529633)}, 
    u'OVV1jSKJ': {u'a': {u'n': u'timelapse'}, u'h': u'OVV1jSKJ', u'k': (1075652685, 899584718, 471199899, 32827924), u'ts': 1370115910, u'p': u'uBUzRayb', u'u': u'BVs8yisX5G4', u't': 1, 'key': (1075652685, 899584718, 471199899, 32827924)}, 
    u'CBEHyJQC': {u'a': {u'n': u'FR1X10.avi'}, u'h': u'CBEHyJQC', u'k': (1095843221, 846021889, 1205770022L, 1642369272), u'ts': 1370115188, 'iv': (1137674974, 26639331, 0, 0), u'p': u'Kc91ADhR', u's': 266668032, 'meta_mac': (2177042245L, 418704470), u'u': u'BVs8yisX5G4', u't': 0, 'key': (43956043, 872103650, 3323826275L, 2031123630, 1137674974, 26639331, 2177042245L, 418704470)}
    }
    """

    listing = []

    directoryDict = {}
    # Get directories
    for index in files:
        currentFile = files[index]
        try:
            filename = currentFile['a']['n']
            directory = currentFile['t']
            current = currentFile['h']
            if directory != int(1): # Save only directories
                continue
            else:
                #print("SAVING " + str(filename) + " in dict " + str(current))
                directoryDict[current] = filename
        except:
            pass


    for index in files:
        currentFile = files[index]

        parent = currentFile['p']
        current = currentFile['h']
        filename = currentFile['a']['n']

        #print("PARENT ID: " + str(parent))
        #print("CURRENT ID: " + str(current))

        try:
            if where == None:
                listing.append(str(directoryDict[parent]) + "/" + str(filename))
            else:
                if directoryDict[parent] == where:
                    listing.append(str(filename))
        except:
            pass

    return listing