示例#1
0
def detection(request):
    while 1:
        result = od1.main()
        print(result)
        if result.count("quit") < 1:
            pringles = result.count("pringles")
            cafe = result.count("cafe")
            doritos = result.count("doritos")
            # if temp>1:
            # if pringles<1 or cafe<1 or doritos<1:
            Token = "P9SHXtrlr0eEeSVx4M04ZRPab7Vbcry42Avk7Luaeva"
            TurnOn_message = "\n" + " 目前架上的商品數量如下:\n" + "Pringles:" + str(
                pringles) + "\n" + "cafe:" + str(
                    cafe) + "\n" + "doritos:" + str(
                        doritos) + "\n請確認是否需要補貨,謝謝\n"
            Time_message = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            MESSAGE = ''
            time.sleep(10)
            MESSAGE = TurnOn_message + Time_message
            print("Send message to Line \n%s\n" % MESSAGE)
            lineTool.lineNotify(Token, MESSAGE)
            time.sleep(10)
        else:
            break
    return redirect('http://localhost:8000/member/memberarea/')
示例#2
0
def processNotifyNews():

    notifySidList = []
    # maybe fetch googlesheet
    googlesheetService = GooglesheetService(
        "1F3cT6ltHQ7gOYxCPSrPJGvMpUt3b5mRJIMR0gJ5ITr8")
    rowList = googlesheetService.getValues("新聞通知清單")

    for row in rowList:
        if len(row) == 0 or row[0] == '' and row[1] == '':
            continue  # 略過空白行
        notifySidList.append(row[0])

    print(notifySidList)

    with open("news.csv", "r", encoding="utf-8") as f1:
        csvRowList = list(csv.reader(f1))
        for csvRow in csvRowList:
            if csvRow[0] in notifySidList and csvRow[6] == "W":
                msg = "{} {} {} {} {}\n\n{}".format(csvRow[0], csvRow[1],
                                                    csvRow[2], csvRow[3],
                                                    csvRow[4], csvRow[5])
                lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], msg)
                csvRow[6] = "Y"
            else:
                csvRow[6] = "N"

    # 寫回 csv 檔
    with open("news.csv", "w", encoding="utf-8", newline="") as f1:
        csv.writer(f1).writerows(csvRowList)
示例#3
0
def fetch():
    
    url = "https://kktix.com/events"
    resp = requests.get(url)
    soup = BeautifulSoup(resp.text, "html.parser")
    
    liList = soup.find("ul", {"class": "event-list"}).findAll("li", {"class": "clearfix"})
    
    with open("kktix.txt", encoding="utf-8") as f1:
        kktixList = list(csv.reader(f1))
    
    with open("kktix.txt", "a", newline="", encoding="utf-8") as f1:
        writer = csv.writer(f1)
        
        messageList = []
        for li in liList:
            title = li.find("h2").find("a").text
            
            description = li.find("div", {"class": "description"}).text
            
            href = li.find("h2").find("a").get("href")
            
            message = title + "\n\n" + description + "\n" + href
            
            if not [href] in kktixList:
                writer.writerow([href])
                messageList.append(message)
        
        if len(messageList) > 0:
            notifyMessage = ""
            for msg in messageList:
                notifyMessage += msg + "\n----------------------------------------\n\n"
            lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], notifyMessage)
示例#4
0
    def fetchAllStockFinalData(self, dt=datetime.datetime.now()):

        url = "http://www.twse.com.tw/exchangeReport/MI_INDEX?response=json&date=%s&type=ALLBUT0999&_=%s" % (
            dt.strftime("%Y%m%d"), int(time.time() * 1000))
        r = requests.get(url)
        print("GET %s\nResponse => %s" % (url, r.json()))

        js = r.json()
        if js.get("stat") != "OK":
            print("%s 查無資料" % (dt.strftime("%Y%m%d")))
            return

        # 因為有 K 值要處理,不能只抓存單一值,必須從頭開始存起,改通知我自己,有新的代號要處理歷史資料
        newStockIdList = []

        for data in js.get("data5"):

            stockId = data[0]

            if data[9].find('red') > 0:
                sign = '+'
            else:
                sign = '-' if data[9].find('green') > 0 else ''

            date = "{}/{}/{}".format(js["date"][0:4], js["date"][4:6],
                                     js["date"][6:8])
            row = [
                date, data[2], data[4], data[5], data[6], data[7], data[8],
                sign + data[10], data[3], "", ""
            ]  # 後面兩個空值是 RSV & K9
            row = self._make_datatuple(row)
            if not os.path.exists("data/{}.csv".format(stockId)):
                #                 with open("data/{}.csv".format(stockId), "a", newline="") as f1:
                #                     writer = csv.writer(f1)
                #                     writer.writerow(["日期","成交股數","成交金額","開盤價","最高價","最低價","收盤價","漲跌價差","成交筆數","RSV","K9"])
                # 先略過,不處理,之後再處理這些新的
                newStockIdList.append(stockId)
                continue

            # 讀出舊的資料
            rowDict = {}
            with open("data/{}.csv".format(stockId), "r",
                      encoding="MS950") as f1:
                for row1 in csv.reader(f1):
                    rowDict[row1[0]] = row1

            if row[3] != None:
                row[3] = format(round(row[3], 2), ".2f")
            if row[4] != None:
                row[4] = format(round(row[4], 2), ".2f")
            if row[5] != None:
                row[5] = format(round(row[5], 2), ".2f")
            if row[6] != None:
                row[6] = format(round(row[6], 2), ".2f")

            rowDict[row[0]] = row

            self.appendDataByRowList(stockId, rowDict)

        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], newStockIdList)
def fetch(sid):
    
    rowList = [['盈餘所屬年度', '股利發放年度', '股東會日期', '除息交易日', '除息參考價(元)', '除權交易日', '除權參考價(元)', '現金股利發放日', '現金股利盈餘', '現金股利公積', '現金股利合計', '股票股利盈餘', '股票股利公積', '股票股利合計', '股利合計', '發放年度平均股價', '年均殖利率(%)']]
    
    url = "https://goodinfo.tw/StockInfo/StockDividendSchedule.asp?STOCK_ID={}".format(sid)
    print(url)
    headers = {
        "User-Agent" : "Chrome/31.0.1650.63"
    }
    r = requests.get(url, headers=headers)
    r.encoding = "utf-8"
    
    if "查無除權息日程訊息" in r.text:
        return rowList

    if "您的瀏覽量異常, 已影響網站速度" in r.text:
        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], "fetchStockDividendSchedule too fast to be blocked")

    soup = BeautifulSoup(r.text, "html.parser")
    trs = soup.find("table", {"class": "solid_1_padding_4_3_tbl"}).findAll("tr", id=re.compile("^row"))
    for tr in trs:
        row = []
        for td in tr.findAll("td"):
            row.append(td.text)
            
        rowList.append(row)

    return rowList
示例#6
0
def main():
    try:
        print("\n---------------------------------")
        print("執行時間 {}".format(datetime.datetime.now().strftime('%Y/%m%d %H:%M:%S')))
        print("---------------------------------")
        fetch()
    except:
        traceback.print_exc()
        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], "fetch kktix data fail")
def rowListToMessage(rowList, rangeName):

    message = ""
    for row in rowList:
        dt = row[2][0:10] + " " + row[2][11:16]
        message += "------------------------------------------\n[%s] [%s]\n------------------------------------------\n" % (
            rangeName, dt)
        message += row[1] + "\n原文連結: " + row[4] + "\n\n"

    print(message)

    lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], message)
示例#8
0
def notifyLineMsg(token, msg, retry=2):
    print("retry times", retry)
    try:
        lineTool.lineNotify(token, msg)
    except ChunkedEncodingError as e:
        print(e)
        retry = retry - 1
        msg = msg[0:len(msg) - 1]
        if retry > 0:
            time.sleep(1)
            notifyLineMsg(token, msg, retry)
        else:
            raise e
def main():
    
    print("# -------------------------- #\n# 執行時間 {} #\n# -------------------------- #".format(datetime.datetime.now().strftime('%Y/%m%d %H:%M:%S')))
    
    sid = "1313"
    fetch(sid)
    detect(sid)
    
    
    # 前面 for 完全部,換通知
    
    if not os.path.exists("changeList.csv"):
        print("無任何異動不需通知")
        return

    print("\n開始進行通知\n")
    with open("changeList.csv", "r") as f1:
        rowList = list(csv.reader(f1))
    msg = "股權異動通知"
    for row in rowList:
        msg += "\n" + str(row)
        print(row)

    code = lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], msg)
    print(code)
    
    os.remove("changeList.csv")
    print("completed.")
示例#10
0
def lineMe():
    token = ""
    msg = "Python 語言整合通訊軟體,恭喜您"
    response = lineTool.lineNotify(token, msg)
    if response == 200:
        print("傳送成功")
    else:
        print("傳送失敗")
示例#11
0
def notifyTo7LineGroup(text):

    lineTool.lineNotify('2D7IaxfEThWOFQJUu6Wpp8kliclIW1o7C0VaDCiaR7V',
                        text)  # 自己的測試 token

    #lineTool.lineNotify('4dpvkMrhwqS5BS20b76f9z8xfZgceRweJ8eiaRLtcGC', text) # 群一
    #time.sleep(2)
    #lineTool.lineNotify('p3LcZxNRx2PRpjZ6oKeoEZxpq5F8EqYjq3OsO96ChyM', text) # 群二
    #time.sleep(2)
    #lineTool.lineNotify('cnL48vx1yPjVGhmbGICvWOipRJJoM1C8Dudde9JFGlW', text) # 群三
    #time.sleep(2)
    #lineTool.lineNotify('XutbtO5bOgyCIdg3kJZ3MZhGakLGMw1JRGpQgbDIK3D', text) # 群四
    #time.sleep(2)
    #lineTool.lineNotify('rMUoZDVl1C5fuRMmH9sUEI4qTgHyfy8lMDQXEh0PTBc', text) # 群五
    #time.sleep(2)
    #lineTool.lineNotify('CHhwARDFMz384a3XoIzS3nNt03nNFH7UG8LX8ooYCJS', text) # 群六
    #time.sleep(2)
    #lineTool.lineNotify('qN59nwm7YStstULdWHZEPh7Z4X77WvcLd7FffgHvGNq', text) # 群七

    logging.info('通知七群完畢')
示例#12
0
def fetchOtcStockIdFormSheet(sheetId, sheetName, token):

    googlesheetService = GooglesheetService(sheetId)

    rowNum = 0
    for value in googlesheetService.getValues(sheetName):
        rowNum += 1

        # header
        if rowNum == 1:
            continue  # header 不繼續下面的邏輯
        if len(value) == 0:
            continue  # 略過空白行
        if value[0] == '':
            continue  # 連股票代號都沒有的,略過

        if stockIdMap.get(value[0], "") == "上櫃":
            stockDataMap[value[0]] = None  # 本來是想放名稱,但這裡沒有
        elif stockIdMap.get(value[0], "") == "":
            print("{} 非上市上櫃目前不支援".format(value[0]))
            lineTool.lineNotify(token, "{} 非上市上櫃目前不支援".format(value[0]))
示例#13
0
def fetch(sid):

    rowList = [[
        '盈餘發放年度', '現金股利盈餘', '現金股利公積', '現金股利合計', '股票股利盈餘', '股票股利公積', '股票股利合計',
        '股利合計', '股利總計現金(億)', '股利總計股票(千張)', '董監酬勞合計(百萬)', '董監酬勞合計佔淨利(%)',
        '員工紅利現金(億)', '員工紅利股票(千張)', '股價年度', '股價統計(元)最高', '股價統計(元)最低',
        '股價統計(元)年均', '年均殖利率(%)現金', '年均殖利率(%)股票', '年均殖利率(%)合計', '盈餘年度',
        'EPS(元)', '盈餘分配率(%)配息', '盈餘分配率(%)配股', '盈餘分配率(%)合計'
    ]]

    url = "https://goodinfo.tw/StockInfo/stockDividendPolicy.asp?STOCK_ID={}".format(
        sid)
    print(url)
    headers = {"User-Agent": "Chrome/31.0.1650.63"}
    r = requests.get(url, headers=headers)
    r.encoding = "utf-8"

    if "查無除權息日程訊息" in r.text:
        return rowList

    if "您的瀏覽量異常, 已影響網站速度" in r.text:
        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"],
                            "fetchstockDividendPolicy too fast to be blocked")
        raise EOFError()

    soup = BeautifulSoup(r.text, "html.parser")
    trs = soup.findAll("table",
                       {"class": "solid_1_padding_4_0_tbl"})[1].findAll("tr")
    for tr in trs:

        if not tr.has_attr("onmouseover"):
            continue

        row = []
        for td in tr.findAll("td"):
            row.append(td.text)

        rowList.append(row)

    return rowList
示例#14
0
def main():

    print("執行時間 {}".format(
        datetime.datetime.now().strftime('%Y/%m%d %H:%M:%S')))

    now = datetime.datetime.now()

    # 取最後一筆資料
    with open("data/t00.csv", encoding="MS950") as f1:
        row = list(csv.reader(f1))[-1]

    # 若日期等於今日才作通知
    if row[0] != now.strftime("%Y/%m/%d"):
        print("無今日資料,不進行通知")
        return

    yestPrice = float(row[6]) - float(row[7])
    pct = round(float(row[7]) / yestPrice * 100, 2)

    msg = "{} 大盤 K 值 {}\n\n大盤指數 {} {} ({:.2f}%)".format(
        row[0], row[10], row[6], row[7], pct)
    msg += "\n"
    msg += composeMsg("0050")
    msg += "\n"
    msg += composeMsg("0056")

    if float(row[10]) >= 80:
        msg += "\n\n## 大盤 K 值已超過 80,建議賣出 0050 ##"
    elif float(row[10]) <= 20:
        msg += "\n\n## 大盤 K 值已低於 20,建議買入 0050 ##"

    # 0056 額外通知訊息
    with open("data/0056.csv", encoding="MS950") as f1:
        row = list(csv.reader(f1))[-1]

    amt = int(row[1]) // 1000
    if amt >= 2000 and amt < 5000:
        msg += "\n\n## 0056 成交量 {} 張,較平常多,可留意是否較低價可買入 ##".format(amt)
    elif amt >= 5000 and amt < 8000:
        msg += "\n\n## 0056 成交量 {} 張,數量偏大,可留意是否較低價可買入 ##".format(amt)
    elif amt >= 8000:
        msg += "\n\n## 0056 成交量 {} 張,異常的高,請留意是否較低價可買入 ##".format(amt)

    k9 = float(row[10])
    if k9 <= 20:
        msg += "\n\n## 0056 K值已低於 20,可考慮低價可買入 ##".format(amt)
    elif k9 >= 80:
        msg += "\n\n## 0056 K值已高於 80,可考慮價差 1元以上賣出 ##".format(amt)

    print(msg)

    # 發 LINE 通知
    lineTool.lineNotify(os.environ["LINE_0050_TOKEN"], msg)
    time.sleep(2)  # delays for n seconds
    lineTool.lineNotify(os.environ["LINE_0050_TOKEN2"], msg)
    time.sleep(2)
    lineTool.lineNotify(os.environ["LINE_0050_TOKEN3"], msg)
    time.sleep(2)
    lineTool.lineNotify(os.environ["LINE_0050_TOKEN4"], msg)
    time.sleep(2)
    lineTool.lineNotify(os.environ["LINE_0050_TOKEN5"], msg)
    time.sleep(2)
    lineTool.lineNotify(os.environ["LINE_0050_TOKEN6"], msg)
    time.sleep(2)
    lineTool.lineNotify(os.environ["LINE_0050_TOKEN7"], msg)
def main():
    print("[INFO] quantifying faces...")
    imagePaths = list(paths.list_images('dataset'))

    # initialize the list of known encodings and known names
    knownEncodings = []
    knownNames = []

    # loop over the image paths
    for (i, imagePath) in enumerate(imagePaths):
        # extract the person name from the image path
        print("[INFO] processing image {}/{}".format(i + 1, len(imagePaths)))
        name = imagePath.split(os.path.sep)[-2]

        # load the input image and convert it from RGB (OpenCV ordering)
        # to dlib ordering (RGB)
        image = cv2.imread(imagePath)
        # cv2.imshow('image',image)
        # cv2.waitKey(0)
        print(imagePath)
        rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

        # detect the (x, y)-coordinates of the bounding boxes
        # corresponding to each face in the input image
        boxes = face_recognition.face_locations(rgb, model='hog')

        # compute the facial embedding for the face
        encodings = face_recognition.face_encodings(rgb, boxes)

        # loop over the encodings
        for encoding in encodings:
            # add each encoding + name to our set of known names and
            # encodings
            knownEncodings.append(encoding)
            knownNames.append(name)

    # dump the facial encodings + names to disk
    print("[INFO] serializing encodings...")
    data = {"encodings": knownEncodings, "names": knownNames}
    f = open('encodings.pickle', "wb")
    f.write(pickle.dumps(data))
    f.close()

    print("[INFO] loading encodings + face detector...")
    data = pickle.loads(open('encodings.pickle', "rb").read())
    detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

    # initialize the video stream and allow the camera sensor to warm up
    print("[INFO] starting video stream...")
    #vs = VideoStream(src=0).start()
    vs = VideoStream(usePiCamera=True).start()
    time.sleep(2.0)

    # start the FPS counter
    fps = FPS().start()

    token = 'vLFoe5SQBochCZsPJcDdct7oqOtcm6HdPD2QyCPyeZm'
    message = 'Notify from LINE, Intruder detected!!!'
    hasSent = False

    # loop over frames from the video file stream
    while True:
        # grab the frame from the threaded video stream and resize it
        # to 500px (to speedup processing)
        frame = vs.read()
        frame = imutils.resize(frame, width=500)

        # convert the input frame from (1) BGR to grayscale (for face
        # detection) and (2) from BGR to RGB (for face recognition)
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

        # detect faces in the grayscale frame
        rects = detector.detectMultiScale(gray,
                                          scaleFactor=1.1,
                                          minNeighbors=5,
                                          minSize=(30, 30),
                                          flags=cv2.CASCADE_SCALE_IMAGE)
        # OpenCV returns bounding box coordinates in (x, y, w, h) order
        # but we need them in (top, right, bottom, left) order, so we
        # need to do a bit of reordering
        boxes = [(y, x + w, y + h, x) for (x, y, w, h) in rects]

        # compute the facial embeddings for each face bounding box
        encodings = face_recognition.face_encodings(rgb, boxes)
        names = []

        # loop over the facial embeddings
        for encoding in encodings:
            # attempt to match each face in the input image to our known
            # encodings
            matches = face_recognition.compare_faces(data["encodings"],
                                                     encoding)
            name = "Unknown"

            # check to see if we have found a match
            if True in matches:
                # find the indexes of all matched faces then initialize a
                # dictionary to count the total number of times each face
                # was matched
                matchedIdxs = [i for (i, b) in enumerate(matches) if b]
                counts = {}

                # loop over the matched indexes and maintain a count for
                # each recognized face face
                for i in matchedIdxs:
                    name = data["names"][i]
                    counts[name] = counts.get(name, 0) + 1

                # determine the recognized face with the largest number
                # of votes (note: in the event of an unlikely tie Python
                # will select first entry in the dictionary)
                name = max(counts, key=counts.get)

            # update the list of names
            names.append(name)

        if len(rects) != 0 and name == "Unknown" and not hasSent:
            print("Intruder!")
            lineTool.lineNotify(token, message)
            hasSent = True

        elif len(rects) != 0 and name != "Unknown":
            print(name)
            hasSent = False
        '''
		# loop over the recognized faces
		for ((top, right, bottom, left), name) in zip(boxes, names):
			# draw the predicted face name on the image
			cv2.rectangle(frame, (left, top), (right, bottom),
				(0, 255, 0), 2)
			y = top - 15 if top - 15 > 15 else top + 15
			cv2.putText(frame, name, (left, y), cv2.FONT_HERSHEY_SIMPLEX,
				0.75, (0, 255, 0), 2)

		# display the image to our screen
		cv2.imshow("Frame", frame)
		'''
        key = cv2.waitKey(1) & 0xFF
        # if the `q` key was pressed, break from the loop
        if key == ord("q"):
            break

        # update the FPS counter
        fps.update()

    # stop the timer and display FPS information
    fps.stop()
    print("[INFO] elasped time: {:.2f}".format(fps.elapsed()))
    print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))

    # do a bit of cleanup
    cv2.destroyAllWindows()
    vs.stop()
示例#16
0
    for row in rowList:
        if len(row) == 0 or row[0] == '' and row[1] == '':
            continue  # 略過空白行
        notifySidList.append(row[0])

    print(notifySidList)

    with open("news.csv", "r", encoding="utf-8") as f1:
        csvRowList = list(csv.reader(f1))
        for csvRow in csvRowList:
            if csvRow[0] in notifySidList and csvRow[6] == "W":
                msg = "{} {} {} {} {}\n\n{}".format(csvRow[0], csvRow[1],
                                                    csvRow[2], csvRow[3],
                                                    csvRow[4], csvRow[5])
                lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], msg)
                csvRow[6] = "Y"
            else:
                csvRow[6] = "N"

    # 寫回 csv 檔
    with open("news.csv", "w", encoding="utf-8", newline="") as f1:
        csv.writer(f1).writerows(csvRowList)


if __name__ == "__main__":
    try:
        main()
    except:
        traceback.print_exc()
        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], "readNews error")
示例#17
0

def main():

    t1 = time.time()
    now = datetime.datetime.now()

    crawler = TWSECrawler()

    # 13:50 分以後才會有資料
    if int(str(now.hour) + format(now.minute, "02")) >= 1350:
        # 爬資料寫到各 csv 檔
        crawler.fetchAllStockFinalData()
        # 爬上櫃資料寫到每日 csv 檔
        crawler.fetchOtcDailyCloseQuotes()

    # 爬大盤資料寫入 csv 檔
    crawler.fetchStockInfo("t00")

    t2 = int(time.time() - t1)
    print("total time {}".format(t2))


if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        traceback.print_exc()
        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"],
                            "fetch_all_stock_data 發生錯誤")
示例#18
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

#Author : GordonWei
#Date : Aug/06/19
#comment : Scrapying ITHome Today's News

import requests, re, time, lineTool
from bs4 import BeautifulSoup

today = time.strftime('%Y-%m-%d')
lineToken = 'Your Line Notify Token'
ithome_site = 'https://www.ithome.com.tw/news'
indexRes = requests.get(ithome_site)
indexSoup = BeautifulSoup(indexRes.text, 'html.parser')
pages = indexSoup.find_all('span', class_='views-field')

for n in pages:
    if n.find('p', text=re.compile(today)):
        if n.find('div'):
            title = n.find('p', class_='title').text
            href = n.find('a')['href']
        botText = (today, title, 'https://www.ithome.com.tw' + href)
        lineTool.lineNotify(lineToken, botText)
示例#19
0
                    and float(data['data']['data'][l]['area']) < 750):
                continue
            if (landtype == '建地'
                    and float(data['data']['data'][l]['area']) < 50):
                continue
            if (landtype == '住宅'
                    and float(data['data']['data'][l]['area']) < 50):
                continue

            price = int(data['data']['data'][l]['price'].replace(',', ''))

            if (price > 5000):
                continue

            msg1 = data['data']['data'][l]['sectionname'] + '【' + landtype + '】'
            msg2 = '面積: ' + str(data['data']['data'][l]['area'])
            msg3 = '總價: ' + data['data']['data'][l]['price'] + '萬'
            msg4 = '單價: ' + data['data']['data'][l]['perarea_str']
            msg5 = data['data']['data'][l]['address']

            landId = data['data']['data'][l]['houseid']
            msg6 = 'https://sale.591.com.tw/home/house/detail/2/' + str(
                landId) + '.html'

            msg = "\n" + msg1 + "\n" + msg2 + "\n" + msg3 + "\n" + msg4 + "\n" + msg5 + "\n" + msg6
            lineTool.lineNotify(token, msg)

    print("Wait 1000 seconds ")
    time.sleep(1000)

conn.close()
示例#20
0
def rowListToMessageAndNotify(rowList, rangeName):

    for row in rowList:

        # 因為時間看起來是美國時間,還要再自己加 8,先拿掉時間顯示
        #         dt = row[1][0:10] + " " + row[1][11:16]
        #         message = "------------------------------------------\n[%s] [%s]\n------------------------------------------\n" %(rangeName, dt)

        message = "  [%s]\n------------------------------------------\n" % (
            rangeName)

        if len(row) >= 6:
            message += row[3] + "\n\n" + row[5] + "\n\n原文連結: " + row[4]
        else:
            message += row[3] + "\n\n原文連結: " + row[4]

#         lineTool.lineNotify(os.environ["LINE_FANS_TOKEN"], message)
#         time.sleep(3)
#         lineTool.lineNotify(os.environ["LINE_FANS_TOKEN2"], message)
#         time.sleep(3)
#         lineTool.lineNotify(os.environ["LINE_FANS_TOKEN3"], message)
#         time.sleep(3)

        lineTool.lineNotify(os.environ["LINE_0050_TOKEN"], message)
        time.sleep(2)  # delays for n seconds
        lineTool.lineNotify(os.environ["LINE_0050_TOKEN2"], message)
        time.sleep(2)
        lineTool.lineNotify(os.environ["LINE_0050_TOKEN3"], message)
        time.sleep(2)
        lineTool.lineNotify(os.environ["LINE_0050_TOKEN4"], message)
        time.sleep(2)
        lineTool.lineNotify(os.environ["LINE_0050_TOKEN5"], message)
        time.sleep(2)
        lineTool.lineNotify(os.environ["LINE_0050_TOKEN6"], message)
        time.sleep(2)
示例#21
0
def processSheet(sheetId, sheetName, notifyLineToken):

    googlesheetService = GooglesheetService(sheetId)
    
    rowNum = 0    
    rowList = []
    msg = ""
    for value in googlesheetService.getValues(sheetName):
        rowNum += 1
        rowList.append(value) # 之後資料要回寫回 sheet
        
        # header
        if rowNum == 1:
            if len(value) <= 10:
                value.append("") 
            columnNum = len(value) # 取 header 的總 column 數
            value[10] = datetime.datetime.now().strftime('%m%d %H:%M:%S')
            continue # header 不繼續下面的邏輯
        
        if len(value) == 0:
            continue # 略過空白行
        # 明細列若欄位不足,先補齊,避免 exception 發生
        if len(value) < columnNum:
            for i in range(columnNum - len(value)):
                value.append("")

        if value[0] == '':
            continue # 連代號都沒有,其他卻還有 #N/A 的值,大家還是會亂搞,防呆

        # 開始比價
        try:
            nowPrice = float(value[4].replace(",", ""))
        except:
            print("something wrong", value[4])
            print(value)
            nowPrice = 5000.0

        wantPrice = value[2]
        
#         if nowPrice != "" and wantPrice != "" and nowPrice <= float(wantPrice):
        if wantPrice != "" and nowPrice <= float(wantPrice):
            if value[10] != datetime.datetime.now().strftime('%Y%m%d'):
                msg += "\n{} ({}) 買進價 {},現價 {},PE: {},買進原因: {}\n".format(value[1], value[0], value[2], value[4], value[8], value[9])
                value[10] = datetime.datetime.now().strftime('%Y%m%d')
        
        if stockIdMap.get(value[0], "") == "上櫃":
#             value[3] = '=(E{}-C{})/C{}'.format(rowNum, rowNum, rowNum)
#             value[4] = '=IFERROR(ARRAY_CONSTRAIN(importXML(CONCATENATE("http://m.wantgoo.com/s/", $A{}),"//*/div[2]/div/div[1]"),1,1))'.format(rowNum)
#             value[5] = 'N/A'
#             value[6] = 'N/A'
#             value[7] = 'N/A'
#             value[8] = 'N/A'
#             print("上櫃資料改由別隻處理")
            pass
        elif stockIdMap.get(value[0], "") == "上市":
            value[3] = '=(E{}-C{})/C{}'.format(rowNum, rowNum, rowNum)
            value[4] = '=GOOGLEFINANCE(CONCATENATE("TPE:", $A{}), "price")'.format(rowNum)
            value[5] = '=GOOGLEFINANCE(CONCATENATE("TPE:", $A{}), "change")'.format(rowNum)
            value[6] = '=GOOGLEFINANCE(CONCATENATE("TPE:", $A{}), "changepct") / 100'.format(rowNum)
            value[7] = '=GOOGLEFINANCE(CONCATENATE("TPE:", $A{}), "volume") / 1000'.format(rowNum)
            value[8] = '=GOOGLEFINANCE(CONCATENATE("TPE:", $A{}), "pe")'.format(rowNum)
        elif stockIdMap.get(value[0], "") == "":
            print("{} 非上市上櫃不支援".format(value[0]))
            lineTool.lineNotify(notifyLineToken, "{} 非上市上櫃目前不支援".format(value[0]))

    # 其實應該只要更新時間欄位就好,其他欄位不要再更新,但我懶的再改了,之後再說
    googlesheetService.updateSheet(sheetName, rowList)

    if msg != '':
        print("notify msg => {}".format(msg), flush=True)
        lineTool.lineNotify(notifyLineToken, msg)
示例#22
0
    out = cv2.VideoWriter('result.avi', fourcc, 20.0, (1024, 576))

    if cap.isOpened() is False:
        print("Error opening video stream or file")
    else:
        cap.set(cv2.CAP_PROP_POS_MSEC, (frame_cnt*85))#可擷取到32個frames
        ret_val, img = cap.read()
        
        image = rotate(img, 90)

        while ret_val:
            if frame_idx > 31:
                #檢查是否要發出Line求救
                if frame_idx > 51:
                    if whether_to_notify(state_history, frame_idx):
                        lineTool.lineNotify(token, "老人家跌倒了")
                        state_history.clear()
                        state_history = [0]*frame_idx
                else:
                    state_history.append(0)
                #載入最新32幀的骨架
                action_predict = np.zeros([1, 32, 36])
                start_idx = frame_idx - 32
                for i in range(32):
                    action_predict[0, i, :] = action_history[start_idx+i]
                #預測
                result = model.predict(action_predict)
                print('Predict:', result)
                c = np.argmax(result)
                print('Action :', c)
                if c < 2:
            row.append(td.text)
#         print(row)
        rowList.append(row)

    with open("ShowSaleMonChart_{}.csv".format(stockId),
              "w",
              encoding="utf-8",
              newline="") as f1:
        cw = csv.writer(f1)
        cw.writerows(rowList)


# def readFile(stockId):
#
#     with open("StockDirectorSharehold_{}.csv".format(stockId), "r", encoding="utf-8", newline="") as f1:
#        rowList = list(csv.reader(f1))
#
#     for row in rowList:
#
#         if int(row[0].split("/")[0]) >= 2016:
#             print(row[0], row[12], row[13], row[14], row[15], row[16])
# #             print(row[0], row[7], row[8], row[9], row[10], row[11])

if __name__ == "__main__":
    try:
        main()
    except:
        traceback.print_exc()
        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"],
                            "fetchShowSaleMonChart error")
示例#24
0
def notifyMe(text):
    lineTool.lineNotify('2D7IaxfEThWOFQJUu6Wpp8kliclIW1o7C0VaDCiaR7V',
                        text)  # 自己的測試 token
示例#25
0
def linePush(msg):
    lineTool.lineNotify(token, msg)
示例#26
0
text = "\n\n"
text += composeLineText(fetchPrice("0056"), 24, 26)
time.sleep(2)
text += "\n\n"
text += composeLineText(fetchPrice("2890"), 9.0, 9.6)
time.sleep(2)
text += "\n\n"
text += composeLineText(fetchPrice("2891"), 19, 24)
time.sleep(2)
text += "\n\n"
text += composeLineText(fetchPrice("2880"), 14.8, 16)
time.sleep(2)
text += "\n\n"
text += composeLineText(fetchPrice("2881"), 35, 60)
time.sleep(2)
text += "\n\n"
text += composeLineText(fetchPrice("2882"), 35, 50)
time.sleep(2)

print(text)

# price2890 = fetchPrice("2890")
# text += "2890 現在價格 : " + str(price2890) +",目標 : 9.6"
# if price2890 >= 9.6:
#     text += "### YES, sale it !"
#
# text += "\n"

token = os.environ["LINE_TEST_TOKEN"]
lineNotify(token, text)
        "User-Agent" : "Chrome/31.0.1650.63"
    }
    r = requests.get(url, headers=headers)
    r.encoding = "utf-8"
    
    if "查無除權息日程訊息" in r.text:
        return rowList

    if "您的瀏覽量異常, 已影響網站速度" in r.text:
        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], "fetchStockDividendSchedule too fast to be blocked")

    soup = BeautifulSoup(r.text, "html.parser")
    trs = soup.find("table", {"class": "solid_1_padding_4_3_tbl"}).findAll("tr", id=re.compile("^row"))
    for tr in trs:
        row = []
        for td in tr.findAll("td"):
            row.append(td.text)
            
        rowList.append(row)

    return rowList


if __name__ == "__main__":
    try:
        main()
    except:
        traceback.print_exc()
        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], "fetchStockDividendSchedule error")
    
示例#28
0
    rowList = []
    for tr in soup.find("table", {"class": "h4"}).findAll("tr"):
        tdList = tr.findAll("td")
        # 過濾掉不是明細的 tr
        if tdList[0].text.strip(
        ) == '有價證券代號及名稱' or tdList[0].get("colspan") != None:
            continue

        sid = tdList[0].text.strip().split(" ")[0].strip()
        sname = tdList[0].text.strip().split(" ")[1].strip()
        isinCode = tdList[1].text.strip()
        onDate = tdList[2].text.strip()
        marketType = tdList[3].text.strip()
        saleCode = tdList[4].text.strip()
        cfiCode = tdList[5].text.strip()

        row = [sid, sname, isinCode, onDate, marketType, saleCode, cfiCode]
        rowList.append(row)

    return rowList


if __name__ == '__main__':
    try:
        main()
    except Exception as e:
        traceback.print_exc()
        msg = traceback.format_exc()
        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], msg)
    r.encoding = "utf-8"

    soup = BeautifulSoup(r.text, "html.parser")

    # get all row data
    rowList = []
    trs = soup.findAll("tr", id=re.compile("^row"))
    for tr in trs:
        row = []
        for td in tr.findAll("td"):
            row.append(td.text)
        rowList.append(row)

    with open("StockDirectorSharehold_{}.csv".format(stockId),
              "w",
              encoding="utf-8",
              newline="") as f1:
        cw = csv.writer(f1)
        cw.writerows(rowList)


if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        print(e)
        traceback.print_exc()
        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"],
                            "fetchStockDirectorSharehold error")
        lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"], e)
示例#30
0
    def fetchStockInfo(self, stockId):

        js = self.crawlStockInfo(stockId)

        # {"userDelay":500,"rtmessage":"   ","rtcode":"0000"}
        if js["rtcode"] == "0000" and js["rtmessage"] != "OK":
            print("response 0000 but rtmessage:[{}], sleep and try again...".
                  format(js["rtmessage"]))
            time.sleep(5)
            js = self.crawlStockInfo(stockId)
            print(js)

        if js["rtcode"] == "0000" and js["rtmessage"] != "OK":
            print("response 0000 but rtmessage:[{}], sleep and try again...".
                  format(js["rtmessage"]))
            time.sleep(5)
            js = self.crawlStockInfo(stockId)
            print(js)

        # 不知道為什麼,有些就是會暫時沒資料
        if js["rtcode"] == "0000" and js["rtmessage"] == "OK" and len(
                js["msgArray"]) == 0:
            lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"],
                                "{} 查詢成功卻無資料".format(stockId))
            print("查詢成功卻無資料")
            return

        if js["rtcode"] == "0000" and js["rtmessage"] == "OK" and js[
                "msgArray"][0].get("o", "") == '':
            lineTool.lineNotify(os.environ["LINE_TEST_TOKEN"],
                                "{} 查詢成功卻無資料".format(stockId))
            print("查詢成功卻無開盤價格")
            return

        if not js["msgArray"][0]["d"] == datetime.datetime.now().strftime(
                '%Y%m%d'):
            print("查無今日資料不繼續處理檔案")
            return

        # 讀舊資料出來
        rowDict = {}
        with open("data/{}.csv".format(stockId), encoding="MS950") as f1:
            for row in csv.reader(f1):
                rowDict[row[0]] = row

        # 先不考慮錯的時候,直接讓它丟出,最外面直接 line notify 錯誤
#         if js["rtcode"] == "0000":

        o = round(float(js["msgArray"][0]["o"]), 2)
        h = round(float(js["msgArray"][0]["h"]), 2)
        l = round(float(js["msgArray"][0]["l"]), 2)
        z = round(float(js["msgArray"][0]["z"]), 2)  # 現價
        y = round(float(js["msgArray"][0]["y"]), 2)  # 昨日價
        v = int(js["msgArray"][0]
                ["v"]) * 1000  # 成交股數 (v 在這邊應該是張數,要自己 * 1000 才會變真實的股數)

        dt = "{}/{}/{}".format(js["msgArray"][0]["d"][0:4],
                               js["msgArray"][0]["d"][4:6],
                               js["msgArray"][0]["d"][6:8])
        diff = "+" + format(round(z - y, 2), ".2f") if z - y > 0 else format(
            round(z - y, 2), ".2f")
        row = [
            dt, v,
            int(v * z),
            format(o, ".2f"),
            format(h, ".2f"),
            format(l, ".2f"),
            format(z, ".2f"), diff, "", "", ""
        ]
        rowDict[row[0]] = row

        self.appendDataByRowList(stockId, rowDict)