コード例 #1
0
ファイル: core.py プロジェクト: aldryn/aldryn-translator
def get_order(provider, data):
    if provider == 'supertext':
        user, api_key = get_creds('SUPERTEXT', ['USER', 'API_KEY'])
        if is_dev():
            url = 'https://dev.supertext.ch/api/v1/translation/order'
        else:
            url = 'https://www.supertext.ch/api/v1/translation/order'
        headers = {'Content-type': 'application/json; charset=UTF-8', 'Accept': '*'}
        r = requests.post(url, data=json.dumps(data, ensure_ascii=False).encode('ascii', 'xmlcharrefreplace'),
                          headers=headers, auth=(user, api_key), verify=verify_ssl())
        return r.content

    else:
        raise NotImplementedError()
コード例 #2
0
import socket
import utils
import ecc.encoding
from ecc.key import Key
import json

creds = utils.get_creds()
print('Loaded creds')

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
my_addr = s.getsockname()[0]
s.close()
print('Local address: ', my_addr)


def fancy_shit(data):
    chunks = data.split(b',')
    print("found {} chunks".format(len(chunks)))
    keys = []
    vals = []
    result = {}
    for chunk in chunks:
        key = ""
        if chr(chunk[0]) == '"':
            print('starting key')
            for char in chunk[1:]:
                if chr(char) == '"':
                    break
                key += chr(char)
                print('building key: ', key)
コード例 #3
0
ファイル: test_utils.py プロジェクト: ColCarroll/newsreader
 def remove_auth(self):
     creds = {k: v for k, v in get_creds(SAMPLE_CREDS).iteritems() if k != 'token'}
     json.dump(creds, open(SAMPLE_CREDS, 'w'))
コード例 #4
0
ファイル: test_utils.py プロジェクト: ColCarroll/newsreader
 def expire_auth(self):
     creds = get_creds(SAMPLE_CREDS)
     creds["expires"] = (
         datetime.datetime.today() - datetime.timedelta(seconds=100)).strftime(DATE_FMT)
     json.dump(creds, open(SAMPLE_CREDS, 'w'))
     self.reader._creds = None
コード例 #5
0
ファイル: test_utils.py プロジェクト: ColCarroll/newsreader
def test_get_creds():
    creds = get_creds()
    for key in ('client_id', 'client_secret', "username", "password"):
        assert_in(key, creds)
        assert_is_not_none(creds[key])
コード例 #6
0
    paramikoModule.close(client)
    time.sleep(5)


while True:
    # Calls Georgios's banner
    utils.banner()
    # Provides the menu options to the user
    answer = utils.menu()

    if answer == '1':

        # Rather than storing creds in the code. Call the get_creds method to get them
        # it will return a dictionary consisting of the username & password variables
        credentials = utils.get_creds()
        # gets the new secret
        secret = utils.get_secret()

        # creating a dictionary for each device to connect to. It could read from a file the IPs...
        # add more routers as needed
        router1 = {
            'server_ip': '10.x.x.x',
            'server_port': '22',
            'user': credentials["username"],
            'passwd': credentials["password"]
        }
        # in case we need to stores the credentials locally on the code
        # router1 = {'server_ip': '10.x.x.x', 'server_port': '22', 'user': '', 'passwd': ''}

        # creating a list of dictionaries (of devices)