Exemple #1
0
    def run(self):
        df = ts.get_industry_classified()

        JsonList = []
        for i in df.index:
            JsonList.append(df.loc[i].to_dict())

        emg = emongo()
        sdb = emg.getCollectionNames("AllStockClass")
        sdb.remove()
        sdb.insert(JsonList)
        emg.Close()
Exemple #2
0
    def run(self):

        if self._init == 1:
            emg = emongo()
            szNotic = emg.getCollectionNames("StockNotices")
            szNotic.remove()
            emg.Close()

        dbl = dblist()
        clist = dbl.getAllCodeList()
        dbl.Close()

        for c in clist:
            cd = c["code"]
            self.getData(cd)
Exemple #3
0
    def run(self):
        df500 = ts.get_zz500s()
        df300 = ts.get_hs300s()

        df800 = pd.DataFrame(df500)
        df800 = df800.append(df300,ignore_index=True)
        df800.sort_values(by="code")

        un800 = json.loads(df800.to_json(orient="records"))

        emg = emongo()
        szCode = emg.getCollectionNames("un800")
        szCode.remove()
        szCode.insert(un800)
        emg.Close()
Exemple #4
0
    def getData(self, code):
        ndf = pd.DataFrame()
        n = 1
        emg = emongo()
        szNotic = emg.getCollectionNames("StockNotices")
        d = {}
        notices = list(
            szNotic.find({code: {
                "$exists": 1
            }}, {
                code: 1,
                "_id": 1
            }))
        if len(notices) == 0:
            while 1:
                df = self.get_notices(code, n)
                if n == 1:
                    ndf = df
                    n += 1
                    continue
                if df.empty == False:
                    ndf = ndf.append(df)
                    n += 1
                else:
                    break
            if ndf.empty:
                return
            d[code] = json.loads(ndf.to_json(orient="records"))

            szNotic.insert(d)
            emg.Close()
        else:
            print code, " is update"
            ndf = self.get_notices(code, n)
            if ndf.empty == True:
                print "ndf is empty"
                emg.Close()
                return

            _id = notices[0]["_id"]
            cdata = notices[0][code]
            ndf = ndf.append(pd.DataFrame(cdata))
            ndf = ndf.drop_duplicates()
            d[code] = json.loads(ndf.to_json(orient="records"))
            szNotic.update({"_id": {"$eq": _id}}, {"$set": d})
            emg.Close()
def main():
    if len(sys.argv) == 2:
        stock = sys.argv[1]
        print "get one stock:", stock

        emg = emongo()
        conn = emg.getCollectionNames("ShareBonus")
        df = _get_ShareBonus_data(stock)
        cjson = df.to_json(orient="records")
        j = json.loads(cjson)
        dt = {}
        dt[str(stock)] = j
        conn.insert(dt)
        emg.Close()
    else:
        print "get all stock"
        getAllShareBonus()
def getAllShareBonus():

    dbl = dblist()
    allCodeList = dbl.getAllCodeList()
    dbl.Close()

    emg = emongo()
    conn = emg.getCollectionNames("ShareBonus")
    conn.remove()

    for post in allCodeList:
        code = post["code"]
        df = _get_ShareBonus_data(code)
        cjson = df.to_json(orient="records")
        j = json.loads(cjson)
        dt = {}
        dt[str(code)] = j

        conn.insert(dt)
    emg.Close()
Exemple #7
0
def main():
    pytm = pyToMongo()
    emg = emongo()
    sdb = emg.getCollectionNames("stockInfo")
    ymk = sdb.find({}, {
        "ym": 1,
        "_id": 0
    }).sort("ym", pymongo.DESCENDING).limit(1)
    if ymk.count() == 0:
        pytm.run(2013, 1)
    else:
        for ym in ymk:
            y = int(ym['ym'][:4])
            m = int(ym['ym'][4:])
            if m < 4:
                m += 1
            else:
                y += 1
                m = 1
            print y, "_", m
            pytm.run(y, m)
    emg.Close()
Exemple #8
0
 def __init__(self):
     self.__conn = emongo()
     self.__sdb = self.__conn.getCollectionNames("stockDB")
Exemple #9
0
    def run(self, year, month):

        stockDB = {}

        print "basics"
        basicDf = ts.get_stock_basics()
        basicDf.rename(columns=lambda x: x.replace('esp', 'eps'), inplace=True)
        stockDB["basics"] = json.loads(basicDf.to_json(orient="index"))

        print "report"
        reportDf = ts.get_report_data(year, month)
        if reportDf is None:
            print "report is None %d, %d" % (year, month)
            return
        else:
            repJson = self.toJson(reportDf)
            stockDB["report"] = repJson


#        print stockDB

        print "profit"
        profitDf = ts.get_profit_data(year, month)
        if profitDf is None:
            print "profitDf is None %d, %d" % (year, month)
        else:
            proJson = self.toJson(profitDf)
            stockDB["profit"] = proJson

        print "operation"
        operationDf = ts.get_operation_data(year, month)
        if operationDf is None:
            print "operationDf is None %d, %d" % (year, month)
        else:
            operJson = self.toJson(operationDf)
            stockDB["operation"] = operJson

        print "growth"
        growthDf = ts.get_growth_data(year, month)
        if growthDf is None:
            print "growthDf is None %d, %d" % (year, month)
        else:
            growJson = self.toJson(growthDf)
            stockDB["growth"] = growJson

        print "debtpaying"
        debtpayingDf = ts.get_debtpaying_data(year, month)
        if debtpayingDf is None:
            print "debtpayingDf is None %d, %d" % (year, month)
        else:
            debJson = self.toJson(debtpayingDf)
            stockDB["debtpaying"] = debJson

        print "cashflow"
        cashflowDf = ts.get_cashflow_data(year, month)
        if cashflowDf is None:
            print "cashflowDf is None %d, %d" % (year, month)
        else:
            cashj = self.toJson(cashflowDf)
            stockDB["cashflow"] = cashj

        DT = {}
        k = str(year) + str(month)
        DT["Info"] = stockDB
        DT["ym"] = k

        emg = emongo()
        sdb = emg.getCollectionNames("stockInfo")

        sdb.insert(DT)
        emg.Close()