2012年9月17日 星期一
2012年9月16日 星期日
[Python] webbrowser example
import sys
import webbrowser
def main():
webbrowser.open_new_tab('http://www.google.com/')
webbrowser.open_new_tab('http://www.yahoo.com/')
if __name__ == '__main__':
sys.exit(main())
HTTP Status Code Definitions
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
200 OK
5xx Server Error
Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents SHOULD display any included entity to the user. These response codes are applicable to any request method.
200 OK
Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request the response will contain an entity describing or containing the result of the action.
解釋:
--2012-09-16 22:15:02-- http://mops.twse.com.tw/mops/web/...
Resolving mops.twse.com.tw... 210.69.240.131
Connecting to mops.twse.com.tw|210.69.240.131|:80... connected.
HTTP request sent, awaiting response... 200 O.K
Length: unspecified [text/html]
Saving to: `...'
5xx Server Error
Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents SHOULD display any included entity to the user. These response codes are applicable to any request method.
解釋:之前碰到,衰。還有一種錯誤也很麻煩,response timeout,連 HTTP status code 都不給你。
2012年9月15日 星期六
金價漲1.9% 上看1800美元
http://www.appledaily.com.tw/appledaily/article/headline/20120915/34510651
金價漲1.9% 上看1800美元
散戶湧拋售潮「真正大戶還沒出手」
2012年09月15日
金價昨創波段新高,有機會衝高至每盎司1800美元。林琨凱攝
【王立德、張琬聆、吳苡辰╱台北報導】受美國實施QE3的激勵,國際金價昨天飆破每盎司1770美元,國內銀樓逐漸出現散戶售金潮。
擴散效應可期
北市金銀珠寶公會理事長李文欽指出,真正擁有大筆實體黃金部位的大戶還沒出手,預料大戶出售目標價直指每盎司1800美元。
國內銀樓昨飾金價格大漲,每台錢賣出價6540元台幣,較前日上漲120元,漲幅1.9%。而台銀黃金存摺牌告賣出價也來到每公克1681元,黃金條塊每公斤168.8萬元。
寶來黃金期信基金經理人方立寬說,量化寬鬆政策如同油門,金價如同汽車,油門踩下後,汽車除了會衝快,還會持續滑行,形同量化寬鬆政策宣布後,金價會大漲,後續還有擴散效應可期。
改加碼其他外幣
台灣銀行貴金屬部副理楊天立則認為,金價中長線仍看多,但能否站穩每盎司1800美元是觀察指標。若能站穩,將有機會挑戰1812~1850美元價位,若出現短線獲利回吐賣壓,金價可能下測至1730~1750美元價位。
除看好黃金走勢外,在外幣投資方面,銀行業也提到,一般民眾此時可適度減少美元,改加碼投資澳幣、紐幣,如果風險忍受度較強的投資人,也可逢低買進。另外人民幣也將有一波升值空間。
至於房地產的投資布局,華固建設總經理洪嘉昇表示,原本QE3的推行會讓民眾去追逐保值型資產,但近期央行對貸款利率與建商土建融資的嚴厲控管,本應對房地產幫助很大的QE3資金,現在影響反而不大。
資金未必進房產
興富發建設發言人廖昭雄直言,若說將有通膨疑慮造成民眾搶購房產也不至於,因為「央行不是白癡,9A總裁彭淮南肯定會先做好調整控制,不會讓通膨發生。」屏東商技學院不動產經營系助理教授楊宗憲也透露,從之前QE1、QE2的歷史看來,美國印鈔票救市頂多讓台灣股市連動,浮濫資金未必流進房地產。
黃金投資 建議
投資人類型╱操作建議
●空手投資人
先建立部分黃金部位,跌時買進,逢高分批賣出。
●已有黃金部位投資人
逢高賣出,金價每盎司1850美元以上時先出清,再依國際金融局勢變化,調整投資策略。
●保守型投資人
黃金回跌至1750美元以下時分批買進,1800美元以上出清。
●積極型投資人
分批買進,金價每盎司突破1820美元時,依國際金融局勢變化,調整投資策略。
資料來源:各投信、銀行
評:請參考 http://www.kitco.com/charts/historicalgold.html 查詢歷史價格,區間看長一點,1975 - 2012,站在高崗上,不死也難。當然還得看 QE3 的反應,但我想這跟美國選舉脫不了關係,總得炒熱一下場子。
2012年9月14日 星期五
[Python] Sanity Test on Cash Flow Statement
import logging
import os
import sys
import logger
class SanityCheckerTxt():
def __init__(self):
self.__logger = logging.getLogger()
self.white_msg = [
'資料庫中查無需求資料',
'無應編製合併財報之子公司',
'外國發行人免申報個別財務報表資訊,請至合併財務報表查詢',
]
self.check_list_prefixes = {
'operating_activity' : [
'營業活動',
],
'investing_activity' : [
'投資活動',
],
'financing_activity' : [
'融資活動',
'理財活動',
'不影響現金流量之融資活動'
],
'net_income' : [
'本年度淨利',
'本期母公司淨利',
'本期合併淨利',
'本期合併淨損',
'本期合併總利益',
'本期合併總損益',
'本期純利',
'本期純益',
'本期純損',
'本期純(損)益',
'本期淨利',
'本期淨純益',
'本期淨益',
'本期淨損',
'本期淨(損)',
'本期稅後純益',
'本期稅後淨利',
'本期損益',
'本期總損益',
'本期(損)純益',
'合併(損)',
'合併純益',
'合併純(損)益',
'合併淨利',
'合併淨損益',
'合併淨損',
'合併總利益',
'合併總純益',
'合併總純損',
'合併總純(損)益',
'合併總淨利',
'合併總淨損',
'合併總損失',
'合併總損益',
'合併總(損)益',
'純益',
'純損',
'純(損)益',
'淨利',
'淨損',
'歸屬於母公司股東之合併純益',
'歸屬於母公司股東之合併淨利',
'歸屬於母公司股東之純益',
'歸屬於母公司股東之淨利',
'繼續營業單位稅後淨利',
'A10000', # t05st36_2384_99_02 and t05st36_2384_99_03
]
}
def check_batch(self, src_dir):
self.__logger.debug('''Check directory: %s''' % src_dir)
for file in os.listdir(src_dir):
self.check(os.path.join(src_dir, file))
#return # for debugging
def check(self, file):
self.__logger.debug(file)
assert os.path.isfile(file)
fd = open(file, 'rb')
content = fd.read()
fd.close()
lines = content.decode('utf-8').split('\n')
# No record - Test if white message
if len(lines) is 1:
msg = lines[0]
if not msg in self.white_msg:
self.__logger.info('''%s => %s''' % (file, msg))
return
# Has record - Test if startswith certain prefixes
check_list = {
'operating_activity' : False,
'investing_activity' : False,
'financing_activity' : False,
'net_income' : False,
}
for line in lines:
normed_line = ''.join(line.strip().split())
normed_line = normed_line.replace('│', '').replace('予', '於')
normed_line = normed_line.replace('(', '(').replace(')', ')')
for key in check_list:
for prefix in self.check_list_prefixes[key]:
if normed_line.startswith(prefix):
check_list[key] = True
break
for key in check_list:
if not check_list[key]:
self.__logger.info('''%s => No %s''' % (file, key))
self.__logger.debug('\n'.join(lines))
def main():
logger.config_root(level=logging.INFO)
c = SanityCheckerTxt()
c.check_batch('./txt/2498');
if __name__ == '__main__':
sys.exit(main())
2012年9月11日 星期二
[C#] 故意鎖住檔案
C# 功力尚未退步,可喜可賀。
using System;
using System.IO;
namespace FileLocker
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("Usage: FileLocker.exe file");
return;
}
String file = args[0];
if (!File.Exists(file))
{
Console.WriteLine("File doesn't exist: {0}", file);
return;
}
LockFile(file);
}
static void LockFile(String file)
{
using (File.Open(file, FileMode.Open, FileAccess.Read, FileShare.None))
{
Console.WriteLine("Press any key to unlock file...");
Console.ReadKey();
}
}
}
}
訂閱:
文章 (Atom)
