{"id":940,"date":"2020-12-19T12:44:24","date_gmt":"2020-12-19T04:44:24","guid":{"rendered":"https:\/\/aichh.com\/?p=940"},"modified":"2020-12-19T12:44:24","modified_gmt":"2020-12-19T04:44:24","slug":"%e6%99%ba%e8%83%bd%e4%ba%92%e8%81%94%e7%bd%91%e6%97%b6%e9%92%9f-teacan2-0%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/aichh.com\/940.html","title":{"rendered":"\u667a\u80fd\u4e92\u8054\u7f51\u65f6\u949f TeaCan2.0\u4ee3\u7801"},"content":{"rendered":"<!--wp-compress-html--><!--wp-compress-html no compression--><p>\u8f6c\u8f7d\u5907\u4efd\u4e00\u4e0b\uff1a<\/p>\n<p>https:\/\/blog.csdn.net\/kim5659\/article\/details\/107103968#comments_12711031<\/p>\n<p>https:\/\/www.waveshare.net\/wiki\/1.5inch_RGB_OLED_Module<\/p>\n<p>\u4ee3\u7801\u662fpython3\u7684\uff0c\u8981\u4e0b\u8f7d\u5c4f\u5e55\u7684\u4f8b\u7a0b\uff0c\u8fd9\u6837\u624d\u4f1a\u6709\u76f8\u5173\u7684\u9a71\u52a8\u548c\u5e93\u3002\u4e0d\u7136\u4ee3\u7801\u4f1a\u51fa\u9519\u3002\u8fd8\u8981\u51e0\u4e2a\u5e93\uff1a<br \/>\nPIL\u5b89\u88c5\uff1a\uff08PIL\u662fPython\u4e00\u4e2a\u5f3a\u5927\u65b9\u4fbf\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff09<\/p>\n<pre>pip install Pillow<\/pre>\n<p>\u519c\u5386\u5e93Borax1.3\u5b89\u88c5 (Borax\u662f\u4e00\u4e2a\u7684 Python3 \u5f00\u53d1\u5de5\u5177\u96c6\u5408\u5e93\uff0c\u4e0d\u9650\u4e8e\u663e\u793a\u519c\u5386)<\/p>\n<pre>pip install borax<\/pre>\n<p>requests\u5e93\uff1a<\/p>\n<pre>python3 -m pip install requests<\/pre>\n<p>\u4ee5\u4e0b\u4e3a\u5168\u90e8\u4ee3\u7801\uff1a\u8fd9\u91cc\u9762\u53ef\u80fd\u4f1a\u6709\u5783\u573e\u4ee3\u7801\u3002<\/p>\n<pre># -*- coding:UTF-8 -*-\r\n\r\n#--------------Driver Library-----------------#\r\nimport RPi.GPIO as GPIO\r\nimport OLED_Driver as OLED\r\n#--------------Image Library---------------#\r\nfrom PIL  import Image\r\nfrom PIL import ImageDraw\r\nfrom PIL import ImageFont\r\nfrom PIL import ImageColor\r\nimport sys\r\nimport os\r\nimport random\r\nimport time\r\nfrom borax.calendars.lunardate import LunarDate\r\nimport json\r\nimport re\r\nimport requests\r\n#-------------Test Display Functions---------------#\r\ndef weather_update():\r\n    global c,d,e,f,filemtime_tianqi\r\n    #\u4e0b\u8f7dweather_mini\u6587\u4ef6\r\n    filetq_city=open('\/var\/www\/html\/tianqicity.txt','r')\r\n    citysetup1=filetq_city.readline()\r\n    citysetup=citysetup1.strip('n')\r\n    filetq_city.close()\r\n    filemtime_tianqi=os.path.getmtime('\/var\/www\/html\/tianqicity.txt')\r\n    Download_addres='http:\/\/wthrcdn.etouch.cn\/weather_mini?city='+citysetup\r\n    #\u628a\u4e0b\u8f7d\u5730\u5740\u53d1\u9001\u7ed9requests\u6a21\u5757\r\n    f=requests.get(Download_addres)\r\n    #\u4e0b\u8f7d\u6587\u4ef6(\u539f\u6587\u4fdd\u5b58)\r\n    with open(\"weather_mini\",\"wb\") as code:\r\n         code.write(f.content)\r\n    file_open=open(\"weather_mini\",'r')\r\n    file=file_open.readline()\r\n    file_open.close()\r\n    if 'invilad' in file:\r\n        c='\u57ce\u5e02\u9519\u8bef'\r\n        d=\"\u9519\u8bef\"\r\n        e=\"\u53c8\u662f\u9519\u8bef\"\r\n        f=\"\u8fd8\u662f\u9519\u8bef\"\r\n    else:\r\n    #\u89e3\u6790weather_mini\u6587\u4ef6\r\n        dataJson=json.load(open('weather_mini',encoding='UTF-8'))\r\n\r\n    #\u63d0\u53d6\u5929\u6c14\u76f8\u5173\u4fe1\u606f\r\n        date=dataJson['data']['forecast'][0]['date']\r\n        tianqi=dataJson['data']['forecast'][0]['type']\r\n        low=dataJson['data']['forecast'][0]['low']\r\n        high=dataJson['data']['forecast'][0]['high']\r\n        fengxiang=dataJson['data']['forecast'][0]['fengxiang']\r\n        fengli=dataJson['data']['forecast'][0]['fengli']\r\n        c=citysetup+':'+tianqi\r\n        d='\u6c14\u6e29:'+low[3:-1]+'\u5230'+high[3:-1]+'\u2103'\r\n        e='\u98ce\u529b:'+re.findall('.*CDATA[(.*)]]',fengli)[0]\r\n        f='\u98ce\u5411:'+fengxiang\r\n\r\ndef nianyueri():\r\n    #\u5e74\u6708\u65e5\u661f\u671f\u519c\u5386\u4f4d\u7f6e\r\n    weeks={'Mon':'\u661f\u671f\u4e00','Tue':'\u661f\u671f\u4e8c','Wed':'\u661f\u671f\u4e09','Thu':'\u661f\u671f\u56db','Fri':'\u661f\u671f\u4e94','Sat':'\u661f\u671f\u516d','Sun':'\u661f\u671f\u65e5'}\r\ndef bianliang():\r\n    global a,b\r\n    a=time.strftime('%Y\u5e74%m\u6708%d\u65e5')\r\n    weeks={'Mon':'\u661f\u671f\u4e00','Tue':'\u661f\u671f\u4e8c','Wed':'\u661f\u671f\u4e09','Thu':'\u661f\u671f\u56db','Fri':'\u661f\u671f\u4e94','Sat':'\u661f\u671f\u516d','Sun':'\u661f\u671f\u65e5'}\r\n    d=weeks[time.strftime('%a')]\r\n    today=LunarDate.today()\r\n    b=today.strftime('\u519c\u5386'+'%M\u6708%D'+' '+d)\r\n\r\ndef Display_Picture(File_Name):\r\n       image = Image.open(File_Name)\r\n       OLED.Display_Image1(image)\r\n\r\ndef shijian():\r\n    image = Image.new(\"RGB\", (OLED.SSD1351_WIDTH, OLED.SSD1351_HEIGHT), \"BLACK\")\r\n    draw = ImageDraw.Draw(image)\r\n    #\u5e74\u6708\u65e5\r\n    draw.text((0,0), a, font = font18, fill = \"yellow\")\r\n    #\u519c\u5386\u661f\u671f\r\n    draw.text((0,21),b, font = font13, fill = \"RED\")\r\n    #\u65f6\u95f4\r\n    draw.text((0,33),time.strftime('%H:%M') , font = font, fill = \"BLUE\")\r\n    #\u5929\u6c14\r\n    draw.text((40,70), c, font = font13, fill = \"WHITE\")\r\n    draw.text((40,85), d, font = font13, fill = \"BROWN\")\r\n    draw.text((40,100), e, font = font13, fill = \"PURPLE\")\r\n    draw.text((40,115), f, font = font13, fill = \"PINK\")\r\n    OLED.Display_Image(image)\r\n#    Display_Picture(\"32.jpg\")\r\n#    while (True):\r\n#        draw.line([(0, 50), (80, 50)], fill = \"WHITE\", width = 24)\r\n#        OLED.Display_Image(image)\r\n#        draw.text((0,33),time.strftime('%H:%M') , font = font, fill = \"BLUE\")\r\n #       OLED.Display_Image(image)\r\n #       time.sleep(1)\r\ntry:\r\n    OLED.Device_Init()\r\n    font = ImageFont.truetype('cambriab.ttf',30)\r\n    font18 = ImageFont.truetype('SIMYOU.TTF',18)\r\n    font13 = ImageFont.truetype('SIMYOU.TTF',13)\r\n    weather_update() \r\n    bianliang()\r\n    while (True):\r\n        time.sleep(0.01)\r\n         #\u66f4\u65b0\u65f6\u95f4\r\n        shijian()\r\n        if time.strftime('%H%M%S')=='000000' or\r\n                time.strftime('%H%M%S')=='060000' or\r\n                time.strftime('%H%M%S')=='120000' or\r\n                time.strftime('%H%M%S')=='180000':\r\n                    weather_update()\r\n\r\n\r\n\r\nexcept:\r\n    print(\"rnEnd\")\r\n    OLED.Clear_Screen()\r\n    GPIO.cleanup()\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h5>\u6700\u540e\u4e0a\u4e00\u5f20\u73b0\u5728\u7684\u56fe\uff0c\u5de6\u4e0b\u89d2\u7684\u7a7a\u4f59\u4f4d\u7f6e\u672c\u6765\u8981\u4e0a\u56fe\u7684\uff0c\u6682\u65f6\u8fd8\u6ca1\u6210\u529f\u3002<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"20200703141022585\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2020\/12\/20200703141022585.png\" width=\"631\" height=\"318\"><\/p>\n<!--wp-compress-html no compression--><!--wp-compress-html-->","protected":false},"excerpt":{"rendered":"\u8f6c\u8f7d\u5907\u4efd\u4e00\u4e0b\uff1a https:\/\/blog.csdn.net\/kim5659\/article\/details\/107103968#comments_12711031 https:\/\/www.wavesh \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[125,163,164],"class_list":["post-940","post","type-post","status-publish","format-standard","hentry","category-jiaocheng","tag-https","tag-pip","tag-python"],"views":263,"_links":{"self":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/comments?post=940"}],"version-history":[{"count":1,"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/940\/revisions"}],"predecessor-version":[{"id":942,"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/940\/revisions\/942"}],"wp:attachment":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/media?parent=940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/categories?post=940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/tags?post=940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}