Beispiel #1
0
def get_funds_info(code2company, table, pageIdx, pages=200):
    url = "http://fund.eastmoney.com/Data/Fund_JJJZ_Data.aspx?t=1&lx=1&letter=&gsid=&text=&sort=zde,asc&page={},{}&dt=1613400650082&atfc=&onlySale=0".format(
        pageIdx, pages)
    js_var = requests.get(url).text

    print(url)

    db = js2py.eval_js(js_var)

    total_pages = int(db['pages'])
    curpage = int(db['curpage'])
    datas = db['datas']
    showday = db['showday']

    print("page download finished!", total_pages, curpage)

    for data in datas:
        fundInfo = FundInfo()
        fundInfo.code = data[0]
        fundInfo.name = data[1]

        dailyTable = DBTable(conn, "FundDaily_{}".format(fundInfo.code),
                             FundDailyRec)

        fundDaily = FundDailyRec()

        try:
            if len(data[3]):
                fundInfo.net_per_unit = float(data[3])
            if len(data[4]):
                fundInfo.net_acc = float(data[4])
            if len(data[7]):
                fundInfo.daily_inc_val = float(data[7])

            if len(data[8]):
                fundInfo.daily_inc_pct = float(data[8])

            fundInfo.buy_ava = (data[9] == u'开放申购')
            fundInfo.sell_ava = (data[10] == u'开放赎回')

            if len(data[17]):
                fundInfo.fee = float(data[17][:-1])

            fundInfo.company_code = code2company[fundInfo.code]
        except:
            pass

        fundInfo.update_date = datetime.now().date()
        table.addRecords([fundInfo])

        fundDaily.date = datetime.strptime(showday[0], "%Y-%m-%d").date()
        fundDaily.dwjz = fundInfo.net_per_unit
        fundDaily.ljjz = fundInfo.net_acc
        fundDaily.zzl = fundInfo.daily_inc_pct

        dailyTable.addRecords([fundDaily])

    if curpage < total_pages:
        get_funds_info(code2company, table, pageIdx + 1, pages)
Beispiel #2
0
def my_task(code, fundCompleted, f):
    if code not in fundCompleted:
        with get_sqlite_conn("fund") as conn:
            table = DBTable(conn, "FundDaily_{}".format(code), FundDailyRec)

            get_net_value(table, code)

            f.write("{}\n".format(code))
Beispiel #3
0
    def __init__(self, player_id):
        self._inventoryTable = DBTable('inventory')
        self.inventory = self._inventoryTable.getEntries(playerID=player_id)
        self.pagelen = 10

        self._userTable = DBTable('userdata')
        self.userdata = self._userTable.getEntry(userID=player_id)

        # todo: load the item index in a static way, so more players access the same index
        self._item_index = DBTable("items")
        self._items = self._item_index.getTable()
        '''
        itemcnt = 0
        for ID, name, desc, rarity, value in self._item_index.getTable():
            self._items.append({"ID": ID, "name": name, "desc": desc, "rarity": rarity, "value": value})
            itemcnt = itemcnt + 1'''

        if self.userdata is None:
            self._userTable.addEntry(["userID"], [player_id])
            self.userdata = self._userTable.getEntry(userID=player_id)
Beispiel #4
0
import requests

from database.DBTable import DBTable
from database.FundInfoRecord import FundInfo


def get_fund_info(code):
    url = "http://fundf10.eastmoney.com/jjjz_{}.html".format(code)
    html = requests.get(url)
    html.encoding = 'utf-8'
    currentPage = BeautifulSoup(html.text, 'lxml')

    dd = currentPage.find('dd', {'id': 'f10_menu_jjgs'})

    company_url = dd.find('a')['href']

    company_code = basename(company_url)[:-5]

    return company_code


if __name__ == "__main__":
    with get_sqlite_conn("fund") as conn:
        fundInfoTable = DBTable(conn, "FundInfo", FundInfo)
        df = fundInfoTable.getDataFrame(None, ['code'])
        for code in df.code.values:
            company_code = get_fund_info(code)
            fundInfoTable.updateRecords({'company_code': company_code},
                                        "code='{}'".format(code))
            print(code, company_code)
Beispiel #5
0
    fundCompleted = set()

    if os.path.exists(filename):
        f = open(filename, 'r+')
        for code in f:
            fundCompleted.add(code.strip())
    else:
        f = open(filename, 'w')

    try:

        with get_sqlite_conn("fund") as conn:
            ## create table FundInfo

            fundInfoTab = DBTable(conn, "FundInfo", FundInfo)

            df = fundInfoTab.getDataFrame(None, ['code'])

        with ThreadPoolExecutor(1) as executor:
            future2code = {
                executor.submit(my_task, code, fundCompleted, f): code
                for code in df.code.values
            }
            for future in concurrent.futures.as_completed(future2code):

                d = future2code[future]

                print(d)
                try:
                    future.result()
Beispiel #6
0
@author: borisw
'''
from database.DBTable import DBRecord, DBTable
from datetime import date
from database.dbCon import get_sqlite_conn


## define the table fields for FundInfo
class FundInfo(DBRecord):
    code = ""
    name = ""
    net_per_unit = 0.0
    net_acc = 0.0
    daily_inc_val = 0.0
    daily_inc_pct = 0.0
    buy_ava = True
    sell_ava = True
    fee = 0.0
    company_code = ""
    update_date = date(2021, 2, 16)

    __keys__ = ['code']


if __name__ == '__main__':
    ## Create the table
    with get_sqlite_conn("fund") as conn:
        ## create table FundInfo
        fundInfoTable = DBTable(conn, "FundInfo", FundInfo)
Beispiel #7
0
        'Referer': 'http://fund.eastmoney.com/Company/default.html'
    }
    js_var = requests.get(url,headers=headers).text
    
    db = js2py.eval_js(js_var)
    
    for rec in db['datas']:

        fundCompanyRec = FundCompany()
        fundCompanyRec.code = rec[0]
        fundCompanyRec.name = rec[1] 
        fundCompanyRec.create_date = datetime.strptime(rec[2],'%Y-%m-%d').date()
        if rec[3].isnumeric():
            fundCompanyRec.fund_num = int(rec[3])
        fundCompanyRec.manager = rec[4]
        if len(rec[7]):
            fundCompanyRec.mgmt_money = float(rec[7])
        fundCompanyRec.star_level = len(rec[8])
        
        table.addRecords([fundCompanyRec])
        

    
    
    
if __name__ == "__main__":
    with get_sqlite_conn("fund") as conn:
        ## create table FundInfo 
        fundCompanyTable = DBTable(conn,"FundCompany",FundCompany)
        get_fund_companies(fundCompanyTable)
    
Beispiel #8
0
class Player:
    def __init__(self, player_id):
        self._inventoryTable = DBTable('inventory')
        self.inventory = self._inventoryTable.getEntries(playerID=player_id)
        self.pagelen = 10

        self._userTable = DBTable('userdata')
        self.userdata = self._userTable.getEntry(userID=player_id)

        # todo: load the item index in a static way, so more players access the same index
        self._item_index = DBTable("items")
        self._items = self._item_index.getTable()
        '''
        itemcnt = 0
        for ID, name, desc, rarity, value in self._item_index.getTable():
            self._items.append({"ID": ID, "name": name, "desc": desc, "rarity": rarity, "value": value})
            itemcnt = itemcnt + 1'''

        if self.userdata is None:
            self._userTable.addEntry(["userID"], [player_id])
            self.userdata = self._userTable.getEntry(userID=player_id)

    def addXP(self, qnt):
        self._userTable.changeEntry("userID", self.userdata.playerID, "xp", self.userdata.xp + qnt)
        self.userdata = self._userTable.getEntry(playerID=self.userdata.playerID)

    def addItem(self, item_id):
        self._inventoryTable.addEntry(["playerID", "itemID"], [self.userdata.playerID, item_id])
        self.inventory = self._inventoryTable.getEntries(playerID=self.userdata.playerID)

    @aesthetic_discord.box
    def getItem(self, item_number) -> str:
        item = self._items[self.inventory[item_number - 1].itemID-1]

        return f"{item.iName} ({item.iRarity}): \n{item.iDesc} "

    @aesthetic_discord.box
    def getInvPage(self, page_number) -> str:
        retstr = ""

        at_position = page_number * self.pagelen
        for itemindex in range(at_position, at_position + self.pagelen):
            if itemindex >= len(self.inventory):
                break

            itemrow = self.inventory[itemindex]
            item = self._items[itemrow.itemID-1]

            retstr = retstr + str(itemindex + 1) + ". " + \
                item.iName + " (" + item.iRarity + ")x"+ str(itemrow.quantity) + "\n"

        if len(self.inventory) == 0:
            retstr = "Non hai oggetti nell'inventario. è ora di grindare!"

        return retstr

    '''
Beispiel #9
0
            pass

        fundInfo.update_date = datetime.now().date()
        table.addRecords([fundInfo])

        fundDaily.date = datetime.strptime(showday[0], "%Y-%m-%d").date()
        fundDaily.dwjz = fundInfo.net_per_unit
        fundDaily.ljjz = fundInfo.net_acc
        fundDaily.zzl = fundInfo.daily_inc_pct

        dailyTable.addRecords([fundDaily])

    if curpage < total_pages:
        get_funds_info(code2company, table, pageIdx + 1, pages)


if __name__ == '__main__':

    ## Create the tables
    with get_sqlite_conn("fund") as conn:
        ## create table FundInfo
        fundInfoTable = DBTable(conn, "FundInfo", FundInfo)

        ## get company code from table
        df = fundInfoTable.getDataFrame(None, ['code', 'company_code'])
        code2company = dict()
        for row in df.itertuples():
            code2company[getattr(row, 'code')] = getattr(row, 'company_code')

        get_funds_info(code2company, fundInfoTable, 1, 200)