Exemplo n.º 1
0
def iciba(date_iciba, save_path_iciba):
    client = pymongo.MongoClient(host='localhost', port=27017)
    db = client['openadoor']
    collection = db['wwwWordsEveryday']
    iciba_info_everyday(collection, date_iciba, save_path_iciba)
    client.close()
    print('iciba done: ' + save_path_iciba)
    return save_path_iciba
Exemplo n.º 2
0
def notify_controller(cmd):
	global g_host, g_port
	addr = (g_host, g_port)
	client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	if(not client.sendto(cmd, addr)):
		logger.debug("client send failed")
		
	time.sleep(1)
	client.close()
Exemplo n.º 3
0
def pic_ocr(url_pic, save_path_pic2json, date_pic2json):
    output_dir = save_path_pic2json[0:-5] + date_pic2json + '.json'
    if os.path.isfile(output_dir):
        print('pic_ocr done: json already exists ' + output_dir)
        return save_path_pic2json[0:-5] + date_pic2json + '.json'
    else:
        appid = "1251627875"
        bucket = "ztfp"
        secret_id = "AKIDUt7A1hcdu0veBWfdS8e0A9wXyDH9sb4L"
        secret_key = "DF7nIbyFLFxToxvhIhjbHl4B6uXyKYbY"
        expired = time.time() + 2592000
        onceExpired = 0
        current = time.time()
        rdm = ''.join(random.choice("0123456789") for i in range(10))
        userid = "0"
        fileid = "tencentyunSignTest"
        info = "a=" + appid + "&b=" + bucket + "&k=" + secret_id + "&e=" + str(expired) + "&t=" + str(current) + "&r="  + str(rdm) + "&u=0&f="
        signindex = hmac.new(secret_key.encode("utf8"), info.encode("utf8"), hashlib.sha1).digest()  # HMAC-SHA1加密
        sign = base64.b64encode(signindex + info.encode("utf8"))  # base64转码
        url = "http://recognition.image.myqcloud.com/ocr/general"
        headers = {'Host': 'recognition.image.myqcloud.com',
                "Content-Length": "187",
                "Content-Type": "application/json",
                "Authorization": sign}
        payload = {"appid": appid,
                "bucket": bucket,
                "url": url_pic}
        r = requests.post(url, json=payload, headers=headers)
        responseinfo = r.json()
        # print(responseinfo)
        # for i_pic in range(0, len(responseinfo['data']['items'])):
        #     print(responseinfo['data']['items'][i_pic]['itemstring'])

        jsobj = json.dumps(responseinfo)
        with open(output_dir, "w") as f:
            f.write(jsobj)
            f.close()
        with open(save_path_pic2json, "w") as f:
            f.write(jsobj)
            f.close()
        # 存入数据库
        client = pymongo.MongoClient(host='localhost', port=27017)
        db = client['openadoor']
        collection = db['wwwPic2Json_THS']
        a = collection.find_one({'date': date_pic2json})
        if a is None:
            data_for_mongo = {'date': date_pic2json,
                              'json': responseinfo}
            collection.insert_one(data_for_mongo)
            client.close()
        print('pic_ocr done: json already write in text file: ' + output_dir)
        return output_dir
Exemplo n.º 4
0
def worker(worker_id, input, output):
	msg = ">>>worker:%2d, pid=%4d" % (worker_id, os.getpid())
	logger.debug(msg)
	global g_host, g_port
	server_addr = (g_host, g_port)
	client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	#
	for func in iter(input.get, 'STOP'):
		ret = request_to_controller(client, server_addr, 'GET_TASK_ID')
		if ret != "STOP":
			task_id = eval(ret)
			result = make_task_query(client, worker_id, task_id, func)
			text = 'TASK_RESULT|ID=%d|CODE=%d|MSG=%s|WORKER=%d' % (task_id, result.code, result.result, worker_id)
			request_to_controller(client, server_addr, text)
			output.put(result)
		else:
			logger.debug("worker:%2d recv STOP flag" % worker_id)
			output.put('STOP')
			break
	client.close()
	logger.debug(">>>worker:%2d finished" % (worker_id,))
Exemplo n.º 5
0
def excel_generate(date_eg):
    datestrtitle = time.strftime('%m.%d', time.localtime(time.time()))
    datestrxls = time.strftime('%Y-%m-%d', time.localtime(time.time()))
    xls = RemoteExcel('D:\\60_openadoor\BlingBlingMoney\\模板.xlsx')
    xls.set_cell('今日', 1, 1, '[' + datestrtitle + ']今日股市股票行情')
    # im = Image.open('D:\\60_openadoor\Pictures_FastStoneCapture\每日一句配图.jpg')
    # img_size = im.size
    # xls.add_pic('今日', 'D:\\60_openadoor\Pictures_FastStoneCapture\每日一句配图.jpg', 2, 1, img_size[0], img_size[1])
    xls.set_cell('今日', 3, 1, '每日一句:')
    client = pymongo.MongoClient(host='localhost', port=27017)
    db = client['openadoor']
    collection = db['wwwWordsEveryday']
    words_everyday_mongodb = collection.find_one({"date": date_eg})
    client.close()
    xls.set_cell('今日', 4, 1, '    ' + words_everyday_mongodb['content'])
    xls.set_cell('今日', 5, 1, '    ' + words_everyday_mongodb['note'])
    xls.set_cell('今日', 7, 1, '    ' + '市场总览:')
    xls.set_cell('今日', 8, 1, '    ' + words_everyday_mongodb['note'])

    xls.save("D:\\60_openadoor\BlingBlingMoney\\" + date_eg + '.xlsx')
    xls.close()
Exemplo n.º 6
0
def get_status_and_log(telescope, logger):

    ##-------------------------------------------------------------------------
    ## Get Status Info
    ##-------------------------------------------------------------------------
    logger.info('#### Starting Status Queries ####')
    status = {'telescope': telescope, 'date': datetime.datetime.utcnow()}
    status = get_telescope_info(status, logger)
    status = get_focuser_info(status, logger)
    if telescope == 'V20':
        status = get_RCOS_info(status, logger)

    ##-------------------------------------------------------------------------
    ## Write to Mongo
    ##-------------------------------------------------------------------------
    done = False
    while done is False:
        try:
            logger.info('Connecting to mongo db at 192.168.1.101')
            client = pymongo.MongoClient('192.168.1.101', 27017)
            db = client.vysos
            status_collection = db['{}status'.format(telescope)]
        except:
            logger.error('Failed to connect to mongo')
        else:
            ## Save new "current" document
            try:
                inserted_id = status_collection.insert_one(status).inserted_id
                logger.info("  Inserted document id: {}".format(inserted_id))
                done = True
            except:
                e = sys.exc_info()[0]
                logger.error('Failed to add new document')
                logger.error('Will wait 10 seconds and try again')
                logger.error(e)
                time.sleep(10)
            client.close()
Exemplo n.º 7
0
                # noinspection PyBroadException
                try:
                    excel_wb.Save()
                except Exception as inst:
                    excel_wb = excel.Workbooks.Open(Filename=file_path + file)
                    excel_ws = excel_wb.Worksheets(ws.name)
                finally:
                    # Grab Table
                    tab = excel_ws.ListObjects("My"+ws.name)
                    # Remove current sorts, and sort by Author,Series,Title
                    tab.Sort.SortFields.Clear()
                    for sortValue in ws.sort_fields:
                        tab.Sort.SortFields.Add(Key=excel_ws.Range("My" + ws.name + "[" + sortValue + "]"), Order=1)
                    tab.Sort.Apply()
                    excel_wb.Save()
            except Exception as inst:
                print("Tried to open", file_path + file, "got error:", inst)
                logging.exception("Failed to open %s error was %s", file_path + file, inst)
            finally:
                if excel:
                    excel.Application.Quit()
                wb.upload_to_dropbox(token)
        if client:
            client.close()
        logging.info("Exiting Program")
        exit()
    else:
        # Otherwise give an error and wait for more input
        logging.warning("Error %s is not a valid upc", upc)
        print("UPC's are only numeric\a")
Exemplo n.º 8
0
    def deal_with_client(self,client):
        while True:
            try:
                client.settimeout(10.0)
                print("listening to client")
                data = client.recv(2)
                if not data:
                    logging.info("Server: connection dropped by client ")
                    client.close()
                    client = None
                    return
                length = str(data.decode())
                MSGLEN = int(length)
                #print(MSGLEN,length)
            except ConnectionResetError as e:
                logging.info("connection forcibly closed by client ")
                client.close()
                client = None
                return
            except ConnectionAbortedError as e:
                logging.info("connection aborted  ")
                client.close()
                client = None
                return
            except socket.timeout:
                logging.info("socket timed out without receiving any data")
                client.close()
                client = None
                return
            except OSError as e:
                logging.info("socket is closed, not a socket, closing connection")
                client.close()
                client = None
                return
            except ValueError as e:
                logging.info("Server: Error converting length of next message to an int, received length was ", str(length))
                client.close()
                client = None
                return
            if length == '':
                return


            chunks = []
            received = 0
            while received < MSGLEN:
                try:
                    client.settimeout(10)
                    chunk  = str(client.recv(min(MSGLEN - received, 2048)).decode())
                except ConnectionResetError as e:
                    logging.info("connection forcibly closed by client")
                    client.close()
                    return
                except ConnectionAbortedError as e:
                    logging.info("connection aborted")
                    client.close()
                    return
                except socket.timeout:
                    logging.info("socket timed out without receiving any data")
                    client.close()
                    return
                if chunk == '':
                    print("no data received after 10 seconds")
                    return
                chunks.append(chunk)
                received +=  len(chunk)
            data = "".join(chunks)

            msg = data.split(",")

            #print ("number of splits " + str(len(msg)))
            if msg[0] == "change":
                logging.info("Server: message received from client %s",msg)
                logging.info("Server: received change market message, new market is" + str(msg[1]))
                if self.currentmarket != str(msg[1]):
                    self.ba.openmarket(msg[1],1)
                    self.currentmarket = str(msg[1])
                if self.currentBetdaqMarket != str(msg[2]):
                    self.bd.changeMarket(str(msg[2]))
                    self.currentBetdaqMarket = str(msg[2])
            elif  msg[0] == "PING":
                pass
            elif "horse:" in msg[0]:
                logging.info("Server: message received from client %s",msg)
                horse = msg[0]
                index = horse.find(":")
                horse = horse[index+1:]
                betType = str(msg[3])
                betNo = int(msg[4])
                settings = self.w.getServerBetSettings()
                odds = float(settings[0 +  (2 * betNo)])
                stake = float(settings[1+  (2 * betNo) ])
                betdaqOdds = float(settings[12 +  (2 * betNo)])
                betdaqStake = float(settings[13 +  (2 * betNo)])
                logging.info("Server: received remote bet %s %f %f %s %i %f %f",horse,odds,stake,betType,betNo,betdaqOdds,betdaqStake)
                fillOrKill = 0
                if settings[2] !="":
                    fillOrKill = int(settings[24])
                self.betThread.add_bet(horse,odds,stake,fillOrKill,betType)
                self.bd.placeBet(horse,betType,betdaqOdds,betdaqStake,fillOrKill)
        client.close()
Exemplo n.º 9
0
def to_html(date_html, save_path, list_path_pic_to_html):

    # 连接数据库读取文章内容
    client = pymongo.MongoClient(host='localhost', port=27017)
    db = client['openadoor']
    collection = db['wwwWordsEveryday']
    words_everyday_mongodb = collection.find_one({"date":  date_html})
    client.close()

    # 标题栏日期红色显示
    title_date = '【' + date_html[4:] + '】'
    # 标题栏内容
    title_fpan = '今日股市股票行情'
    # 每日一句英语
    words_en = words_everyday_mongodb['content']
    # 每日一句翻译
    words_zh = words_everyday_mongodb['note']
    # 每日一句配图,压缩成和上证日K一样的尺寸
    url_words_everyday = list_path_pic_to_html[0]

    # 上证今日K线,共有30根K线
    url_sh000001_daily = list_path_pic_to_html[1]
    url_ztnum_hist = list_path_pic_to_html[2]
    url_zffb = list_path_pic_to_html[3]
    url_detail_pv = list_path_pic_to_html[4]
    url_hotstock = list_path_pic_to_html[5]
    text_ztfp = list_path_pic_to_html[6]
    f = open(save_path, 'w')
    message = """

    <h2><font color=red>%s</font>%s</h2>
    <p> </br></p>

    <img src=%s></img>
    <p> </br></p>

    <p>%s</br>%s</p>
    <p> </br></p>
    <img src=%s></img>
    <p> </br></p>

    <img src=%s></img>
    <p> </br></p>
    <img src=%s></img>
    <p> </br></p>
    <img src=%s></img>
    <p> </br></p>
    <img src=%s></img>
    <p> </br></p>
    <p> %s</p>
    <p> </br></p>

    """ % (
        title_date,
        title_fpan,
        url_words_everyday,
        words_en,
        words_zh,
        url_sh000001_daily,
        url_ztnum_hist,
        url_zffb,
        url_detail_pv,
        url_hotstock,
        text_ztfp)

    f.write(message)
    f.close()
    print('to_html done: ' + save_path)
    return save_path