class CandlePricingAPI(Oanda):
    """
    API to get the current pricing

    """

    def __init__(self, access_token, account_id, csv_path):
        super().__init__(access_token, account_id)
        self.csv_handler = CSVHandler(csv_path)

    def get_candle_price(self):
        url = BASE_API_URL + '/v3/accounts/' + \
            self.account_id + '/candles/latest'
        res = requests.get(url,
                           headers={'Authorization': 'Bearer ' +
                                    self.access_token},
                           params={'candleSpecifications': 'EUR_USD:M1:B'})

        if(res.status_code != 200):
            # need to handle error
            pass

        data = json.loads(res.text)
        row_data = data['latestCandles'][0]['candles'][-1]['bid'].values()
        self.csv_handler.save_to_csv(row_data)
def main():
    parser = ArgumentParser()
    parser.add_argument('--csv_file', '-c', dest='csv_file', required=True, metavar='FILE',
                        help='CSV containing region metadata',
                        type=lambda x: valid_file(parser, x))
    parser.add_argument('--api_version', '-a', dest='api_version', required=False,
                        default=strftime('%Y-%m-%d'),
                        help='Version of API')
    parser.add_argument('--basedir', '-b', dest='base_dir', required=True,
                        help='Base directory to write feeds out to')
    args = parser.parse_args()
    csv = CSVHandler(args.csv_file)
    csv.restructure()

    version_directory = os.path.join(args.base_dir, args.api_version)
    latest_directory = os.path.join(args.base_dir, 'latest')
    schema = SchemaBuilder()
    schema.add_object(csv.data)
    schema.to_schema()

    for directory in (version_directory, latest_directory):
        if not os.path.exists(directory):
            os.makedirs(directory)
        with open(os.path.join(directory, 'regions.json'), 'w') as f:
            f.write(csv.to_json())
        with open(os.path.join(directory, 'regions.schema.json'), 'w') as f:
            f.write(schema.to_json())

    generate_version_list(args.base_dir)
    def comentar_sorteio(self, repetir=False):
        driver = self.driver
        time.sleep(30)
        driver.get(url)

        try:
            csv = CSVHandler()
            if escolha == 1:
                comentarios = csv.open_csv("P:\\Python\\Programas\\BOT_Instagram\\planilhas\\111.csv")
            elif escolha == 2:
                comentarios = csv.open_csv("P:\\Python\\Programas\\BOT_Instagram\\planilhas\\2.csv")
            else:
                comentarios = csv.open_csv("P:\\Python\\Programas\\BOT_Instagram\\planilhas\\333normal.csv")
            driver.find_element_by_class_name('Ypffh').click()
            campo_comentario = driver.find_element_by_class_name('Ypffh')
            time.sleep(random.randint(2, 5))
            self.digite_como_uma_pessoa(
                random.choice(comentarios), campo_comentario)
            print(campo_comentario)
            time.sleep(random.randint(30, 40))
            driver.find_element_by_xpath(
                "//button[contains(text(), 'Publicar')]").click()
            time.sleep(60)
        except Exception as e:
            print(e)
            time.sleep(5)
示例#4
0
    def test_read_sudoku_from_valid_csv(self):
        sudoku_invalid_size = -1
        csv_import = CSVHandler()
        sudoku = csv_import.get_rows_sudoku_data('testinvalidcsv.csv', ',')
        expected = "316578492\n" + \
                   "529134768\n" + \
                   "487629531\n" + \
                   "263415987\n" + \
                   "974863125\n" + \
                   "851792643\n" + \
                   "138947256\n"

        self.assertEquals(sudoku[0][0], expected)
        self.assertEquals(sudoku[0][1], sudoku_invalid_size)
示例#5
0
 def __init__(self):
     """
     Contructor class Import Data class in charge to import sudokus
     data from different inputs such as csv or txt
     """
     self.csv_handler = CSVHandler()
     self.cmd_handler = CMDHandler()
示例#6
0
    def test_read_sudoku_from_valid_csv(self):
        sudoku_size = 9
        csv_import = CSVHandler()
        exp_val = "316578492\n" + \
                  "529134768\n" + \
                  "487629531\n" + \
                  "263415987\n" + \
                  "974863125\n" + \
                  "851792643\n" + \
                  "138947256\n" + \
                  "692351874\n" + \
                  "745286319\n"

        
        sudoku = csv_import.get_rows_sudoku_data('testvalidcsv.csv', ',')
        self.assertEquals(exp_val, sudoku[0][0])
        self.assertEquals(sudoku_size, sudoku[0][1])
示例#7
0
def doesCommitteeExist(committee):
    """
    Args:
        committee: list of information about a committee.

    Returns:
        boolean which is true if and only if the committee
        is in the CSV file.
    """
    emailFile = CSVHandler(EMAIL_FILE_LOCATION)
    contents = emailFile.read()
    isInList = False
    print(committee)
    for x in contents:
        print(x)
        if (x[0] == committee[0]):
            isInList = True
    return isInList
示例#8
0
class ImportData:
    extension_file_csv = ".csv"
    
    def __init__(self):
        """
        Contructor class Import Data class in charge to import sudokus
        data from different inputs such as csv or txt
        """
        self.csv_handler = CSVHandler()
        self.cmd_handler = CMDHandler()
    
    def read_sudoku_data_from_file(self, sudoku_file):
        """
        Read the sudoku data form files such as csv or txt
        Returns False if the data are invalid or the file was not
        able to read, return a matrix[][] wihich contains all the
        sudoku data and their sudoku size

        Keyword arguments:
        sudoku_file -- the path of the file which contains the
                       sudoku data

        """
        ext = self.get_extension_file(sudoku_file)
        matrix_sudoku = []
        if ext == self.extension_file_csv:
            matrix_sudoku = self.csv_handler.get_rows_sudoku_data(sudoku_file, ",")
        return matrix_sudoku

    def read_sudoku_data_from_line(self, line):
        """
        Read the sudoku data form a line entered form comand line
        Return a matrix[][] wihich contains the sudoku data and
        its sudoku size

        Keyword arguments:
        line -- the line string entered by the user

        """
        matrix_sudoku = self.cmd_handler.get_rows_sudoku_data(line)
        return matrix_sudoku
    
    def get_extension_file(self, filename):
        """
        Gess the extension of a given filename

        Keyword arguments:
        filename -- the filename to guess the extention

        """
        double_extensions = ['tar.gz', 'tar.bz2']
        root , ext = os.path.splitext(filename)
        if any([filename.endswith(x) for x in double_extensions]):
            root, first_ext = os.path.splitext(root)
            ext = first_ext + ext
        return ext
示例#9
0
def main():
    all_people_query_set = PeopleQuerySet(foreign_keys={'species': SpeciesQuerySet()}).get_all()
    top_10_people_by_appearances = all_people_query_set.order_by('films_count')[0:10]
    top_10_people_by_appearances_order_by_height = top_10_people_by_appearances.order_by('height')
    top_10_people_by_appearances_order_by_height.resolve_foreign_keys()

    csv_file = CSVHandler(items=top_10_people_by_appearances_order_by_height.items,
                          fields={'name': 'name', 'species': 'species', 'height': 'height',
                                  'appearances': 'films_count'})

    HTTPBin().send_file(file=csv_file.file_path)
示例#10
0
class StreamListener:
    def __init__(self, lstm_model, csv_path):
        self.counter = 0
        self.csv_handler = CSVHandler(csv_path)
        self.lstm_model = lstm_model

    def on_data(self, data):
        if(self.counter > MAX_RETRIEVE):
            return False
        else:
            self.handle_data(data)
            return True

    def handle_data(self, data):
        try:
            price = data['bids'][0]['price']
            time = data['time']
            row_data = [time, price]
            self.csv_handler.save_to_csv(row_data)
        except Exception as e:
            raise e
class TestCSVHandler:
    testFile = CSVHandler(TEST_FILE_LOCATION)

    def testOpenFile(self):
        assert self.testFile != None

    def testRead(self):
        contents = self.testFile.read()
        print(contents)

        assert contents == TEST_FILE_CONTENTS

    def testWrite(self):
        self.testFile.write([])
        contents = self.testFile.read()
        assert contents == []

        self.testFile.write(TEST_FILE_CONTENTS)
        contents = self.testFile.read()
        assert contents == TEST_FILE_CONTENTS
示例#12
0
    def test_write_csv_file(self, mock_csv):
        class DummyStructure:
            def __init__(self, text1, value1, text2):
                self.text1 = text1
                self.text2 = text2
                self.value1 = value1

        tmp_file = TestFileContent(content='')
        csv = CSVHandler(items=[DummyStructure('text1', 2, 'text2')],
                         fields={'header_text1': 'text1', 'header_value1': 'value1', 'header_text2': 'text2'},
                         file_path=tmp_file.filename)

        mock_csv.writer.assert_called_once()
        calls = [call().writerow({'header_text1': '', 'header_value1': '', 'header_text2': ''}.keys()),
                 call().writerow(['text1', '2', 'text2'])]
        mock_csv.writer.assert_has_calls(calls)
        self.assertEqual(mock_csv.writer.call_args.args[0].name, tmp_file.filename)
        self.assertEqual(mock_csv.writer.call_args.kwargs['delimiter'], ',')
        self.assertEqual(mock_csv.writer.call_args.kwargs['quotechar'], '"')
        self.assertEqual(mock_csv.writer.call_args.kwargs['quoting'], mock_csv.QUOTE_MINIMAL)
示例#13
0
 def testNumbersAreRoughlyCorrect(self):
     emailFile = CSVHandler(EMAIL_FILE_LOCATION)
     contents = emailFile.read()
     socCount = len(contents)
     assert socCount > 380
     assert socCount < 400
示例#14
0

app = Flask(__name__)
# 扩展在创建应用实例时初始化,一种方式是将应用实例传入构造函数
bootstrap = Bootstrap(app)

# 商品ID与回调函数
# 按销量选了三个牌子的,1 小米 2 公牛 3 良品 4 飞利浦
param_list = [['4354506', 'fetchJSON_comment98vv3810'],
                ['492036', 'fetchJSON_comment98vv203899'],
                ['5342704', 'fetchJSON_comment98vv774'],
              ['4130061', 'fetchJSON_comment98vv4666'],
              ]

# init
csv_handler = CSVHandler()
part = None
w2v = W2V()
his = {}

# 。。。
graph = tf.get_default_graph()


@app.route('/')
def index():
    return render_template('index_bootstrap.html')


@app.route('/crawler')
def crawler():
示例#15
0
 def __init__(self, lstm_model, csv_path):
     self.counter = 0
     self.csv_handler = CSVHandler(csv_path)
     self.lstm_model = lstm_model
    emailContainer = pageSoup.find('div', class_="outlet__header--contact t__def-bl--pri contact__align mgn__t--1 mgn__b--1")
    email = ""
    if emailContainer != None:
        email = emailContainer.find('a').text

    return [name, email]

def getAllInfo(links):
    result = []

    # Setup for the progess meter.
    completion = 0
    step = 100/len(links)

    # Get the page info from each link.
    for link in links:
        currInfo = extractSocietyInfo(link)
        result.append(currInfo)

        # Advance and print out how far through the program is.
        completion += step
        print("{}% done".format(round(completion)))
    return result

# Get society info.
societyUrls = findSocietyPages()
socInfo = getAllInfo(societyUrls)

# Write it all to a CSV.
testFile = CSVHandler(EMAIL_FILE_LOCATION)
testFile.write(socInfo)
示例#17
0
 def test_read_sudoku_from_empty_csv(self):
     expected = []
     csv_import = CSVHandler()
     sudoku = csv_import.get_rows_sudoku_data('empty.csv', ',') 
     self.assertEquals(sudoku, expected)
示例#18
0
 def test_read_sudoku_from_non_exist_csv(self):
     csv_import = CSVHandler()
     sudoku = csv_import.get_rows_sudoku_data('non_exist.csv', ',')
     expected = [] 
     self.assertEquals(sudoku, expected)
示例#19
0
 def __init__(self, access_token, account_id, csv_path):
     super().__init__(access_token, account_id)
     self.csv_handler = CSVHandler(csv_path)
示例#20
0
 def test_no_fields_provided(self):
     with self.assertRaises(CSVHandler.MissingCSVFields):
         CSVHandler(items=[])