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 / 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 / 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
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 / 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 =[]
@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 / 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 / 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 / infix_to_postfix.py
Created November 26, 2015 11:58
simple python
def bi_exp_tree(expstr):
""" infix to postfix.
>>> bi_exp_tree("(a+(b*c))")
'abc*+'
>>> bi_exp_tree("((a+b)*(z+x))")
'ab+zx+*'
>>> bi_exp_tree("((a+t)*((b+(a+c))^(c+d)))")
'at+bac++cd+^*'
"""
result = ""
@lanfon72
lanfon72 / rmdict.py
Last active December 10, 2015 06:13
snippet
def rm_dict(dicts, keyword, recursive=True):
""" remove a keyword(k-v pair) from (nest) dict. default is recursived.
:param: dicts - an dict (nested allow).
:param: keyword - an tuple with 2 values, means (key, value).
:param: recursive - recursive search, default is True.
... admonition : doctest string below.
pretty a as:
a = \
{
'name':'adam',
def try_else(x, y):
a = lambda x, y: x % y
b = lambda x, y: x / y
try:
result = a(x,y) + b(x,y)
f = open('Cookie', 'w+')
except ZeroDivisionError as z:
print(z)
# divide by zero.
except PermissionError as p: