def __init__(self, code=None): self.fund_code = code last_quarter_time = time.localtime(time.time() - 3 * 30 * 24 * 3600) year = time.strftime("%Y", last_quarter_time) date = time.strftime("%m-%d", last_quarter_time) index = get_quarter_index(date) quarter_index = year + '-Q' + str(index) self.quarter_index = quarter_index connect_instance = connect() self.connect_instance = connect_instance self.cursor = connect_instance.cursor()
def store(data, collection): try: client = connect() database = client['flowers'] document = database[collection] document.insert_one(data) client.close() return except Exception as e: return e
def update(_id, data, collection): try: client = connect() database = client['flowers'] document = database[collection] find_record = {"_id": _id} update_values = {"$set": data} document.update_one(find_record, update_values) client.close() return except Exception as e: raise e
def generate(name_type, language, amount=1): connection = connect.connect() cursor = connection.cursor(cursor_factory=psycopg2.extras.DictCursor) generator_module = import_module('tools.name_generator.' + language) generator = getattr(generator_module, name_type)(cursor) names = generator.generate(amount) sb_logger = logger.get_logger('name_generator') sb_logger.debug("Name generator called with name_type: {} language: {} amount: {}".format( name_type, language, amount)) if len(names) == 0: sb_logger.warning("No names generated.") return False else: sb_logger.debug("{} names generated.".format(len(names))) return names
def build_db(filename='media/words.txt'): # Establish connection to PostgreSQL DB conn = connect() # Cursor object cur = conn.cursor() print('Building dictionary...') with open(filename, 'r') as input_file: for line in input_file: # Word in words.txt word = line.strip() # Definition from wordnet syns = wordnet.synsets(word) # If a definition exists if syns: sql = """INSERT INTO dictionary(word, definition) VALUES(%s, %s);""" # TODO - Add error checking here cur.execute(sql, (word, syns[0].definition())) conn.commit() cur.close() conn.close() print("Words added to DB")
def __init__(self): self.quarter_index = get_last_quarter_str() self.quarter_date = get_quarter_date(self.quarter_index) connect_instance = connect() self.connect_instance = connect_instance self.cursor = connect_instance.cursor()
import re import sys sys.path.append(os.getcwd() + '/src') from time import sleep import pandas as pd from bs4 import BeautifulSoup from selenium.webdriver.support.ui import WebDriverWait from db.connect import connect from lib.mysnowflake import IdWorker from utils.index import get_star_count, bootstrap_thread from utils.login import login_morning_star connect_instance = connect() cursor = connect_instance.cursor() ''' 判读是否当前页一致,没有的话,切换上一页,下一页操作 ''' def text_to_be_present_in_element(locator, text, next_page_locator): """ An expectation for checking if the given text is present in the specified element. locator, text """ def _predicate(driver): try: element_text = driver.find_element_by_xpath(locator).text if int(element_text) != int(text):
def __init__(self): self.quarter_index = '2021-Q1' connect_instance = connect() self.connect_instance = connect_instance self.cursor = connect_instance.cursor() self.lock = Lock()
def __init__(self): connect_instance = connect() self.connect_instance = connect_instance self.cursor = connect_instance.cursor() self.lock = Lock()
# -*- coding:UTF-8 -*- ''' Desc: 从基金的持仓中统计股票出现频率 File: /index.py Project: src File Created: Monday, 22nd March 2021 12:08:36 am Author: [email protected] ----- Copyright (c) 2020 Camel Lu ''' import pymysql from pprint import pprint from db.connect import connect cursor = connect().cursor() if __name__ == '__main__': page_start = 0 page_limit = 10000 stock_sql_join = '' for index in range(10): stock_sql_join = stock_sql_join + \ "t.top_stock_%s_code, t.top_stock_%s_name" % ( str(index), str(index)) + "," # print(stock_sql_join[0:-1]) stock_sql_join = stock_sql_join[0:-1] # print(stock_sql_join) sql_query_season = "SELECT t.fund_code," + stock_sql_join + \ " FROM fund_morning_stock_info as t WHERE t.quarter_index = '2020-q4' AND t.stock_position_total > 20 LIMIT %s, %s ;" cursor.execute(sql_query_season, [page_start, page_limit]) # 执行sql语句