網頁

顯示具有 google 標籤的文章。 顯示所有文章
顯示具有 google 標籤的文章。 顯示所有文章

2020年10月5日 星期一

send external IP from gmail


要申請 GMail 應用程式密碼,需要開啟 兩步驟驗證
選取應用程式時,雖然有郵件,但要選擇 其他

#!/usr/bin/python3
import urllib.request
from ipaddress import ip_address
import smtplib

def GetExternalIP():
    try:
        ip_b = urllib.request.urlopen("https://api.ipify.org").read()
    except:
        return ''
    ip_s = ip_b.decode('utf-8')
    try:
        ip_address(ip_s)
        return ip_s
    except:
        return ''
        
def GetBackupIP():
    try:
        file = open('/tmp/ExternalIp.txt', 'r')
        ip = file.readline()
        file.close()
    except:
        return ''
    return ip

def WriteBackupIP(ip):
    try:
        file = open('/tmp/ExternalIp.txt', 'w')
        file.write(ip)
        file.close()
    except:
        return

def SendMail(ip):
    smtp = smtplib.SMTP('smtp.gmail.com', 587)
    smtp.ehlo()
    smtp.starttls()
    smtp.login('name@gmail.com', 'lkmvemxzkegzrhwqj')
    from_addr = 'name@gmail.com'
    to_addr = 'name@yahoo.com.tw'
    msg = 'Subject:External IP\n' + ip + '\n'
    status = smtp.sendmail(from_addr, to_addr, msg)
    if status == {}:
        print('SendMail success!')
    else:
        print('SendMail fail!')
    smtp.quit

external_ip = GetExternalIP()
print('external ip {}'.format(external_ip))
backup_ip = GetBackupIP()
print('backup ip {}'.format(backup_ip))
if external_ip != '':
    if external_ip != backup_ip:
        SendMail(external_ip)
WriteBackupIP(external_ip)

2017年3月29日 星期三

透過 Google Map API 取得高度

參考 Google Maps Elevation API

https://maps.googleapis.com/maps/api/elevation/json?locations=99.999,99.9999&key=xxxxx

{
   "results" : [
      {
         "elevation" : 123.7428283691406,
         "location" : {
            "lat" : 99.1729,
            "lng" : 999.6859
         },
         "resolution" : 152.7032318115234
      }
   ],
   "status" : "OK"
}

2016年10月13日 星期四

Google Driver Web Page

原先可以正常使用的 語言學習 網站,近期一直不穩,甚至完全不能使用
之後查明原因為 Google 要停止這個功能

網路上有人建議使用 GitHub,但試過後發現,GitHub 可能也不支援了

目前將網頁搬至 000webhost,免費網路空間,目前感覺很棒
雖然該網站曾經被駭客入侵,但是我想它會改善,何況我也只是放單純的網頁


2016年9月6日 星期二

SpeechSynthesisUtterance 無法說中文

之前參考 Speech Synthesis API 製作 語音學習站
發現其中 中文的發音 在部分電腦可以正常發音,有些則不行

之後參考 SpeechSynthesisUtteranceGetting Started with the Speech Synthesis API 修正


// Chrome loads voices asynchronously.
window.speechSynthesis.onvoiceschanged = function(e) {
  var synth = window.speechSynthesis;
  voices = synth.getVoices();
  var voice_1 = document.getElementById('voice_1');
  while (voice_1.options.length) {
    voice_1.remove(0);
  }
  var voice_2 = document.getElementById('voice_2');
  while (voice_2.options.length) {
    voice_2.remove(0);
  }
  voices.forEach(function(voice, i) {
  var opt1 = document.createElement("option");
  opt1.textContent = voice.name + ' (' + voice.lang + ")";
  opt1.setAttribute('data-lang', voice.lang);
  opt1.setAttribute('data-name', voice.name);
  if (voice.lang == "en-US") {
    opt1.selected = true;
  }
  voice_1.appendChild(opt1);
});


2015年10月22日 星期四

2015年1月22日 星期四

利用 gmail 傳送 email

測試一直失敗,而後收到 googole 寄給我的一封信
重要的內容如下:

您可以改用 Google 開發的應用程式 (例如 Gmail) 存取帳戶 (建議做法),或是前往https://www.google.com/settings/security/lesssecureapps 變更相關設定,為您的帳戶停用最新安全性標準。

點入上述網頁,進入 安全性較低的應用程式,點選 啟用
重新寄信即可

gmail -> yahoo
mail.SetLogin("gingrenn@gmail.com");
mail.SetPassword("ingrenn1234");
  mail.SetSenderName("mark chen");
  mail.SetSenderMail("gingrenn@gmail.com");
//   mail.SetReplyTo("user@yahoo.com.tw");
  mail.SetSubject("The message");
  mail.AddRecipient("ingrenn@yahoo.com.tw");

yahoo -> gmail
mail.SetLogin("ingrenn");
mail.SetPassword("mark1234");
  mail.SetSenderName("ingrenn");
  mail.SetSenderMail("ingrenn@yahoo.com.tw");
//   mail.SetReplyTo("user@yahoo.com.tw");
  mail.SetSubject("The message");
  mail.AddRecipient("gingrenn@gmail.com");



2014年12月23日 星期二

Google API

錯誤訊息
{"responseData": null, "responseDetails": "Suspected Terms of Service Abuse. Please see http://code.google.com/apis/errors", "responseStatus": 403}

到此申請帳號
https://developers.google.com/custom-search/v1/using_rest?hl=zh-TW


https://script.google.com/macros/s/AKfycbwwz9O_uKzZtpd3RPkuZLbQkueQUsDYHaEFhmi7PNXvzv_UrFo/exec?id=1Gt9Fe1WbNBSe1pMzqF50Lv1HBAnq7C_Hwh0lfTWVumM

"http://translate.google.com.tw/translate_tts?" +
      "ie=UTF-8&q=" + text + "&tl=" + lang + "&total=1&idx=0" +
      //"ie=UTF-8&q=" + escape(text) + "&tl=" + lang + "&total=1&idx=0" +
      "&textlen=" + text.length;