Skip to content

Instantly share code, notes, and snippets.

@e96031413
e96031413 / flask_to_heroku.py
Created February 20, 2020 06:37
Deploy Your Python Flask Web To Heroku
# Just a record of how to deploy flask to heroku
# original post from https://blog.heron.me/damn-simple-python-web-server-on-heroku-ba67cad2fb18
# 1.Create a new project folder:
$ PROJECT=<WHATEVER YOUR PROJECT NAME>
$ mkdir $PROJECT && cd $PROJECT
# 2.Add requirements.txt inside:
Flask==1.0.3
gunicorn==19.9.0
@e96031413
e96031413 / create_qrcode.py
Created February 21, 2020 11:35
Create Your QRCode with 3 lines only
# pip install qrcode
import qrcode
img = qrcode.make("http://yourURL.com")
img.save("QRcode.png")
@e96031413
e96031413 / line_bot_sdk.py
Created February 22, 2020 03:29
紀錄linebot官方sdk的一些使用方式
from linebot.models import (
MessageEvent, TextMessage, TestSendMessage, StickerMessage, StickerSendMessage, ConfirmTemplate, TemplateSendMessage, MessageAction, URIAction, LocationMessage
)
### TextSendMessage
### StickerSendMessage:只有官方預設的四組貼圖包可以使用
def handle_message(event):
@e96031413
e96031413 / download_from_gd.py
Created February 24, 2020 00:31
Download specific file from Google Drive
from __future__ import print_function
import os
import io
import time
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload, MediaIoBaseDownload
from httplib2 import Http
from oauth2client import file, client, tools
# 權限必須
@e96031413
e96031413 / google_cloud_vision_api.py
Created February 24, 2020 02:35
Google Cloud Vision API Example
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]=r"yourPath.json"
# Instantiates a client
client = vision.ImageAnnotatorClient()
#下載
!wget --content-disposition <url>
#解壓縮ZIP
!apt-get install unzip
!unzip 'filename.zip' -d <path>
#解壓縮RAR
!apt-get install unrar
!unrar e 'filename.rar'
@e96031413
e96031413 / csv_translation_with_googletrans.py
Created February 27, 2020 01:03
Translate Your CSV file to specific language with googletrans
# install googletrans using pip
!pip install googletrans
# Importing the necessary libraries
import pandas as pd
import googletrans
from googletrans import Translator
# Reading and storing the CSV file as a dataframe
df = pd.read_csv('path/to/yourFile.csv')
@e96031413
e96031413 / web_entities
Created March 1, 2020 05:38
A demo of Google vision API web_entities
web_entities {
entity_id: "/g/11fs7n3mgw"
score: 1.1109451055526733
description: "Jacana Ecological Education Park"
}
web_entities {
entity_id: "/m/029xmf"
score: 1.0777499675750732
description: "Pheasant-tailed jacana"
}
@e96031413
e96031413 / python_download_example.py
Created March 5, 2020 08:27
使用tqdm進度條、使用requests下載、使用split()方法進行檔名建立的範例
from tqdm import tqdm
import requests as req
url = "https://abc.com.tw/123.jpg"
def download(url):
filename = url.split('/')[-1] #可以觀察其filename的寫法做為參考
r = req.get(url, stream=True)
with open(filename, 'wb') as f:
for data in tqdm(r.iter_content(1024)):
@e96031413
e96031413 / label_image.py
Created March 13, 2020 01:24
2020年3月13日:可正常在Jetson Nano上執行的Tensorflow Lite官方範例
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,