Skip to content

Instantly share code, notes, and snippets.

View lanfon72's full-sized avatar
πŸ’­
Nothing new

Lanfon lanfon72

πŸ’­
Nothing new
View GitHub Profile
@lanfon72
lanfon72 / primes.py
Created November 20, 2015 08:44
an generator for primes in range.
def primes(start, end):
""" return an generator for primes in range.
>>> next(primes(2,3))
2
>>> list(primes(2,3))
[2]
>>> list(primes(1,3))
[1, 2]
>>> list(primes(5,3))
[3]
@lanfon72
lanfon72 / zf.py
Created November 10, 2015 12:58
a simply funtion for retain unzipfile timestamp.
import os
import time
from zipfile import ZipFile
def unpack(filename, extract_dir=None):
if not extract_dir:
extract_dir = os.path.basename(filename).replace('.zip', '')
with ZipFile(filename) as zf:
for zi in zf.infolist():
@lanfon72
lanfon72 / 99.py
Created September 14, 2015 05:32
nite*nite in one line.
>>> print('\n'.join([''.join(["%d*%d=%2s "%(i,j,i*j) for i in range(1,10)]) for j in range(1,10)]))
1*1= 1 2*1= 2 3*1= 3 4*1= 4 5*1= 5 6*1= 6 7*1= 7 8*1= 8 9*1= 9
1*2= 2 2*2= 4 3*2= 6 4*2= 8 5*2=10 6*2=12 7*2=14 8*2=16 9*2=18
1*3= 3 2*3= 6 3*3= 9 4*3=12 5*3=15 6*3=18 7*3=21 8*3=24 9*3=27
1*4= 4 2*4= 8 3*4=12 4*4=16 5*4=20 6*4=24 7*4=28 8*4=32 9*4=36
1*5= 5 2*5=10 3*5=15 4*5=20 5*5=25 6*5=30 7*5=35 8*5=40 9*5=45
1*6= 6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 7*6=42 8*6=48 9*6=54
1*7= 7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 8*7=56 9*7=63
1*8= 8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64 9*8=72
1*9= 9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
@lanfon72
lanfon72 / insert.py
Created June 2, 2015 05:03
insert influx data.
#!/usr/bin/env python
#coding:utf8
from datetime import datetime
from influxdb import InfluxDBClient
import fileinput
import ast
client = InfluxDBClient("localhost", 8086, 'guest', 'guest', 'twER')
files = open('temp').read().splitlines()
points =[]
import sys
def print_lol(the_list,indent=False,level=0,fh=sys.stdout):
for each_item in the_list:
if isinstance(each_item,list):
print_lol(each_item,indent,level+1,fh)
else:
if indent:
for tab_stop in range(level):
print("\t",end='',file=fh)
print(each_item,file=fh)
@lanfon72
lanfon72 / HSN.csv
Created February 25, 2015 07:15
Hospital serial number.
We can't make this file beautiful and searchable because it's too large.
hospital name, serial number
θ‘›η”Ÿη¦εˆ©ιƒ¨θ‡ΊεŒ—ι†«ι™’εŸŽε€εˆ†ι™’, 0101090019
θ‡ΊεŒ—εΈ‚η«‹θ―εˆι†«ι™’, 0101090517
θ‘›η”Ÿη¦εˆ©ιƒ¨εŸΊιš†ι†«ι™’, 0111070010
ζ–°εŒ—εΈ‚η«‹θ―εˆι†«ι™’, 0131020016
θ‘›η”Ÿη¦εˆ©ιƒ¨ζ¨‚η”Ÿη™‚ι€Šι™’, 0131060010
θ‘›η”Ÿη¦εˆ©ιƒ¨θ‡ΊεŒ—ι†«ι™’, 0131060029
θ‘›η”Ÿη¦εˆ©ιƒ¨ε…«ι‡Œη™‚ι€Šι™’, 0131230012
θ‘›η”Ÿη¦εˆ©ιƒ¨ι‡‘ι–€ι†«ι™’, 0190030516
εŸΊιš†εΈ‚η«‹ι†«ι™’, 0211070012
@lanfon72
lanfon72 / cch.py
Created February 25, 2015 06:59
parse Chimei Jiali Hospital live ER status board.
#!/usr/bin/env ptyhon
#coding:UTF-8
import requests, json, re
html = requests.get('http://www.chimei.org.tw/%E6%80%A5%E8%A8%BA%E5%8D%B3%E6%99%82%E8%A8%8A%E6%81%AF/main.aspx')
pending = re.findall('">(.+?)</font>',html.text)[35:]
pending[2:4] = []
values = [ int(ele) for ele in pending[1:] ]
keys = ['pending_doctor', 'pending_ward', 'pending_icu', 'pending_bed']
report = { key:value for value, key in zip(values, keys) }
@lanfon72
lanfon72 / clh.py
Created February 25, 2015 06:57
parse Chimei Liuying Hospital live ER status board.
#!/usr/bin/env ptyhon
#coding:UTF-8
import requests, json, re
html = requests.get('http://www.chimei.org.tw/%E6%80%A5%E8%A8%BA%E5%8D%B3%E6%99%82%E8%A8%8A%E6%81%AF/main.aspx')
pending = re.findall('">(.+?)</font>',html.text)[21:28]
pending[2:4] = []
values = [ int(ele) for ele in pending[1:] ]
keys = ['pending_doctor', 'pending_ward', 'pending_icu', 'pending_bed']
report = { key:value for value, key in zip(values, keys) }
@lanfon72
lanfon72 / cmh.py
Last active August 29, 2015 14:16
parse ChiMei Hospital live ER status.
#!/usr/bin/env python
#coding:UTF-8
import requests, json, re
html = requests.get('http://www.chimei.org.tw/%E6%80%A5%E8%A8%BA%E5%8D%B3%E6%99%82%E8%A8%8A%E6%81%AF/main.aspx')
pending = re.findall('">(.+?)</font>',html.text)[7:14]
pending[2:4] = []
values = [ int(ele) for ele in pending[1:] ]
keys = ['pending_doctor', 'pending_ward', 'pending_icu', 'pending_bed']
report = { key:value for value, key in zip(values, keys) }
@lanfon72
lanfon72 / ntuh.py
Last active August 29, 2015 14:15
parse ntuh live ER status board
#!/usr/bin/env python
#coding:UTF-8
import requests, re, json, os
from datetime import datetime
os.environ['TZ'] = 'ROC'
requests.packages.urllib3.disable_warnings()
html = requests.get('https://reg.ntuh.gov.tw/EmgInfoBoard/NTUHEmgInfo.aspx')
pending = re.findall(u'<td>(.+?)δΊΊ</td>', html.text)
#parse like ['0', '2', '75', '4', '10']