except ã§ã¨ã©ã¼ãæå®ããªãã£ãæã«ã©ããªã¨ã©ã¼ãçºçãããè¦ã
try: hogehoge() except: print sys.exc_info()[0]
ã£ã¦æ¸ããã¨ãã¦ãã
id:nishiohirokazu å çã«
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
ã£ã¦ããã¨ããã
[0]ã¯1å¹´å¾ã«å°ãç¾½ç®ã«ãªããã
ã¨æãã¦ããã ããï¼ï¼ï¼
1å¹´å¾ã®èªåãããªãããããããã£ã¦è¨ãã¨ããæå³ã§
絶対è¨ããåãªãééããªãè¨ãã
ãã¨ã0çªç®ãä½ãªã®ãããã¥ã¡ã³ãè¦ã¦èª¿ã¹ãã®ããã©ããã¨ããããã
ããã¾ããã§ããï¼ï¼
åãè¨ãã¨æãã®ã§æ¸ãç´ãã¾ãï¼ï¼ï¼
twitter 㧠60 æ¥ä»¥ä¸çºè¨ãç¡ã人ã remove ãã
ãã¤ã®ã¾ã«ãã Twitter ã« Follow å¶éã¨ãåºæ¥ã¦
è²ã
ãªäººã®çºè¨ãè¦ããã®ã« Follow 追å åºæ¥ãªããªã£ã¦
ã³ã³ãã¥ã¼ã¿ã®çã«äººéæ§ã®å¦çè½åã«å¶éãããããããã¼ãã¨
ãæãã®ã¿ãªãã¾ããã«ã¡ã¯
ãªã¼ãã³ã½ã¼ã¹ã¨ãã¶ã¼ã«ã¢ãã«ã®å¾¡ç¥ã«åå åºæ¥ãªãã¦ãã¿ããåã§ããã
ã¿ãªãããããããããã§ããï¼
ãããªãããªã§ Twitter ã«ããã¤ãã¦ã
ããµãã¼ãã«é£çµ¡ãã¦ãå¶é解é¤ããã¤ããã¯ãã¼YOï¼ï¼ã
ã¨è¨ããã¦ãã¾ãã¾ããã
ãã¨ãã£ã¦ããã¤ããã¾ã¾ãªã®ãç²¾ç¥è¡çä¸è¯ããªãã®ã§
60 æ¥ä»¥ä¸çºè¨ã®ç¡ãã¦ã¼ã¶ã remove ããã¹ã¯ãªããæ¸ãã¾ããã
pit 㨠simplejson ãå
¥ã£ã¦ãã°åãã¯ãã§ãï½ï½ï½ï½
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys, simplejson, urllib2, urllib from pit import Pit class TwitterClone(object): def __init__(self, user, passwd,url): self.user = user self.passwd = passwd self.url = url def post(self, text): text = text.encode('utf-8') self.getOpener().open(self.url + 'statuses/update.json', urllib.urlencode({'status':text})) def destroyFriend(self,id): url = self.url + ('friendships/destroy/%s.json' % id) r = self.getOpener().open(url,{}) data = simplejson.loads(r.read()) return data def getTimeline(self): url = self.url + 'statuses/friends_timeline.json' r = self.getOpener().open(url) data = simplejson.loads(r.read()) return data def getReplies(self): url = self.url + 'statuses/replies.json' r = self.getOpener().open(url) data = simplejson.loads(r.read()) return data def getFriends(self,page=1): url = self.url + 'statuses/friends.json?' + urllib.urlencode({'page':page}) r = self.getOpener().open(url) data = simplejson.loads(r.read()) return data def getOpener(self): passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, self.url , self.user, self.passwd) authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) opener.addheaders = [('User-agent', 'TwitterCloneClient(http://d.hatena.ne.jp/jYoshiori/)')] return opener if __name__ == '__main__': twitter_config = Pit.get('twitter.com',{'require' : { 'user' : 'Your twitter name', 'password' : 'Your twitter password' }}) twitter = TwitterClone(twitter_config['user'], twitter_config['password'], 'http://twitter.com/') import rfc822 from datetime import datetime, timedelta from time import sleep lastMonth = datetime.now() - timedelta(days=60) wait = 45 removeCount = 0 print 'start' for index in range(1,1000): print 'page ' + str(index) friends = twitter.getFriends(index) if 0 == len(friends): break for user in friends: if user.has_key('status'): date = datetime(*rfc822.parsedate(user['status']['created_at'])[:7]) if lastMonth > date: print '%s is remov. last update %s' % (user['screen_name'],date) twitter.destroyFriend(user['id']) removeCount += removeCount sleep(wait) else : print '%s is remov.' % user['screen_name'] twitter.destroyFriend(user['id']) removeCount += removeCount sleep(wait) sleep(wait) print 'finish!!. %s remove' % str(removeCount)
ããã¾ãããã¤ã API å¶éã«å¼ã£ããããªãããã«
sleep ã 45ç§ å
¥ãã¦ã¾ãã®ã§ãå¯ãã¾ãã«ã§ãèµ·åãã¦ããã°æã«ã¯çµã£ã¦ãã¨æãã¾ãã
ã¡ãªã¿ã«åã¯
4800人ããã â 3286人
ã«ãªãã¾ããã
ã³ã¢ãªãºã ããå¹æ大ã§ãï¼ï¼
â» å¹æã¯å人ã«ãã£ã¦å·®ãããã¾ãã
super() ã§ã®çå
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
解決 ï¼mechanize.Browser ã object ãç¶æ¿ããªãå¤ãã¿ã¤ãã®ã¯ã©ã¹ã ã£ãã¿ãã
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
ãã㯠OK
>>> class Foo(object): def __init__(self,text): super(Foo,self).__init__(self) ... >>> foo = Foo('test')
ã§ãmechanize.Browser ç¶æ¿ãã¦è¦ªã®ã³ã³ã¹ãã©ã¯ã¿å¼ã¼ãã¨ããã
>>> import mechanize >>> class MyBrowser(mechanize.Browser): ... def __init__(self,userid,passwd): ... super(MyBrowser,self).__init__(self) ... >>> foo = MyBrowser('test','test') ------------------------------------------------------------ Traceback (most recent call last): File "<ipython console>", line 1, in <module> File "<ipython console>", line 3, in __init__ TypeError: super() argument 1 must be type, not classobj
ãªãã§ï¼ï¼ï¼ï¼
æãã¦ã¨ãã人ï¼ï¼ï¼
... super(MyBrowser,self).__init__(self)
ã
... mechanize.Browser.__init__(self)
ã«ããã°åããã ãã©ããªãããã¢ã¤ãªãï¼ï¼
æ±æ¢ããï¼ï¼å¤§å¤ã§ãï¼ï¼
åãè¯ãããã£ã¦ãªãã®ã§ããã大å¤ã§ãï¼ï¼
ç¾äººæè¨ã®ç»åãèªåã®ãµã¼ãã«ä¿åãã¦å
¬éãã¦ã人ããã¾ãï¼ï¼
http://image.baidu.jp/i?tn=baiduimage&ct=201326592&cl=2&word=site%3Abijint.com&lm=-1&z=0
ããã£ã¦ãã£ããä¸å³ãã§ãããï¼ï¼
è¯ããããã¾ãããã©ï¼ï¼
権å©ã«åºã¥ãã対å¿ãã¨ããã¦é ãã¹ãã ã¨æãã¾ãï¼ï¼ï¼
æ å½/æ±æ¢ 2009/03/12 02:28 ãã¤ãç¾äººæè¨ãæè¦ãã¦é ãããããã¨ããããã¾ãã
æè¦ããã¦é ãã¾ããã
ç¾å¨ãå½ç¤¾ã¯ãã©ã¤ãã·ã¼ããªã·ã¼ã«éåããèªå°ã使ç¨ã®åãããã®ãååããé¡ããã¦ããã¾ãã
3æ¥ä»¥å ã«å ¬éã使ç¨ã®åãããè¡ããªãå ´åã権å©ã«åºã¥ãã対å¿ãã¨ããã¦é ãå ´åããããã¾ãã
ãååå®ãããé¡ããã¾ãã
æ±æ¢
http://d.hatena.ne.jp/jYoshiori/20090311/1236768388#c1236792483
[email protected]
RE: ç¾äººæè¨ã®ç»åãã¡ã¤ã«ã欲ãã
http://d.hatena.ne.jp/Yamashiro0217/20090310/1236674979
ã®ã¯ã¦ã¶ã®ã¿ã°ã«ä½æ
ã Python ã¿ã°ããã£ãã®ã§ã
ãã㯠Python ã§æ¸ãã£ã¦äºããªãã¨æã£ã¦æ¸ãã¦ã¿ã¾ããã
import sys,os,urllib,time;[[[globals().__setitem__('url','http://www.bijint.com/jp/img/photo/%02d%02d.jpg' % (i, j))] and [globals().__setitem__('file',open(os.path.basename(url), 'wb'))] and [file.write(urllib.urlopen(url).read())] and [file.close()] and [time.sleep(5)] for j in range(60)] for i in range(24)]
ä¸è¨ã¨ã®éãã¯åãå¤éã§ã¯ç¡ãã®ã§ sleep å
¥ãã¦ã¿ããããã§ããããï¼
ã¨ã©ã¼å¦çã¨ãã¯ãã¦ã¾ããï¼ï¼
ãå©ç¨ã¯è¨ç»çã«ï¼ï¼
RE:pythonã®å¼æ°ã«ãã*hogeã¨ã**mapã¨ã
http://d.hatena.ne.jp/a2c/20090301/1235909666
ãèªãã§â¦â¦
>>> def func(userid,password): ... print userid , password ... >>> hoge= {'userid':'foo','password':'bar'} >>> func(**hoge) foo bar >>> def func2(foo,bar): ... print foo , bar ... >>> hoge=[1,2] >>> func2(*hoge) 1 2
é¢æ°ãå¼ã³åºãå´ã§ã使ããï¼ï¼ï¼ï¼
ããã¯è¶
便å©ï¼ï¼ï¼
>>> value = '2008-03-10' >>> datetime(*map((lambda x: int(x)),value.split('-'))) datetime.datetime(2008, 3, 10, 0, 0)
LDR ã®æªèªãã¯ã¦ãªã°ã©ãã¸æ稿ãã
id:tfunato ã«
ãããï¼Python ã§ãåºæ¥ãã!!ã
ã¨ï¼è¨ã£ãæåï¼ã³ã¼ããæãã¦ã¿ã
#!/usr/bin/env python # -*- coding: utf-8 -*- from hatenagraph import HatenaGraph from pit import Pit import urllib2 hatena_conf = Pit.get('hatena.ne.jp',{'require' : {'userid':'Your hatena.ne.jp userid','password':'Your hatena.ne.jp password'}}) livedoor_conf = Pit.get('livedoor.com',{'require' : {'userid':'Your livedoor.com userid'}}) r = urllib2.urlopen('http://rpc.reader.livedoor.com/notify?user=%s' % livedoor_conf['userid']) count = r.read().replace('|','') graph = HatenaGraph(hatena_conf['userid'],hatena_conf['password']) graph.post_data('LDRæªèªæ°',count)
ããï¼HatenaGraph ã®å®è£ æ¸ããªãããããªãâ¦â¦