Last active
August 29, 2015 14:04
-
-
Save kb10uy/fbaa5e909d254245e4e0 to your computer and use it in GitHub Desktop.
最近のふぁぼから画像を探して落とすツール
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #coding: utf-8 | |
| ################################################################ | |
| #使い方 | |
| #IronPythonとCoreTweetを用意してね! | |
| # | |
| #0.予めTwitterのAPIキーとアクセスキーを取得して設定します | |
| # | |
| #1.このファイルと同じフォルダにCoreTweet.dllとNewtonsoft.Json.dllを置きます | |
| # | |
| #2.コマンドラインを起動してipy.exeにパスを通します | |
| # set PATH=%PATH%;C:\ほげほげ\IronPython-X.X.X | |
| # みたいにすればいいと思います(環境に合わせて変えてね) | |
| # | |
| #3.このファイルを置いたディレクトリに移動して | |
| # ipy getfavimg.py | |
| # | |
| #4.しばらく待つと最大で最新1000件のふぁぼの中から画像を探してfavimgフォルダに落としてくれます | |
| # | |
| #5.レートに引っかかんないようにまた実行するとその続きから取得してくれます | |
| ################################################################ | |
| import clr | |
| clr.AddReferenceByPartialName("System.Core") | |
| clr.AddReferenceByPartialName("CoreTweet") | |
| from System import * | |
| from System.Text import * | |
| from System.Linq import * | |
| from System.IO import * | |
| from System.Net import * | |
| from System.Collections.Generic import * | |
| from CoreTweet import * | |
| import System | |
| clr.ImportExtensions(System.Linq) | |
| at="318376822-8drIuaOZ45Li1xaztYp67s1mye9vI0BsKC1qrCgE" | |
| ats="p2qS3XfWVfRQHlvGBenwKBdORCue2xTbO0tq4ok" | |
| ck="0I1fnElUHzoofKHtYem6A" | |
| cs="R9UaZHBzjoBKXkYi7A6r6F0T3SwbrEaMqhWrvTZ2lM" | |
| prm=Dictionary[String,Object]() | |
| lm=0 | |
| if (File.Exists("getfavimg.txt")): | |
| lm=long(File.ReadAllText("getfavimg.txt")) | |
| if (Directory.Exists("favimg")==False): | |
| Directory.CreateDirectory("favimg") | |
| token=Tokens.Create(ck,cs,at,ats) | |
| wc=WebClient() | |
| for c in range(1,5): | |
| Console.WriteLine("Getting Favorites... ("+c.ToString()+"/5)") | |
| prm.Clear() | |
| prm["count"]=200 | |
| if (lm!=0): | |
| prm["max_id"]=lm | |
| try: | |
| favs=token.Favorites.List(prm) | |
| lm=favs.Last().Id-1 | |
| except TwitterException: | |
| Console.WriteLine("Rate Limit! Sorry!") | |
| break | |
| for i in favs: | |
| if (i.Entities!=None)and(i.Entities.Media!=None): | |
| i.Text=i.Text.Replace("\\","¥").Replace("/","/").Replace(":",":").Replace("*","*").Replace("?","?").Replace("\"","”").Replace("<","<").Replace(">",">").Replace("|","|") | |
| url=i.Entities.Media[0].MediaUrl.ToString() | |
| Console.WriteLine("Detected : "+i.Id.ToString()) | |
| Console.WriteLine(" "+url) | |
| fn="@"+i.User.ScreenName+" "+i.Id.ToString() | |
| if (url.EndsWith(".jpg")): | |
| wc.DownloadFile(url,"favimg/"+fn+".jpg") | |
| elif (url.EndsWith(".png")): | |
| wc.DownloadFile(url,"favimg/"+fn+".png") | |
| elif (url.EndsWith(".gif")): | |
| wc.DownloadFile(url,"favimg/"+fn+".gif") | |
| File.WriteAllText("getfavimg.txt",lm.ToString()) | |
| Console.WriteLine("Completed!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment