main.py 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538
  1. #!/usr/bin/env python
  2. # -*- coding: iso-8859-15 -*-
  3. """
  4. $Id$
  5. This file is part of the anontwi project, http://anontwi.03c8.net
  6. Copyright (c) 2012/2013/2014/2015 by psy <epsylon@riseup.net>
  7. anontwi is free software; you can redistribute it and/or modify it under
  8. the terms of the GNU General Public License as published by the Free
  9. Software Foundation version 3 of the License.
  10. anontwi is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  13. details.
  14. You should have received a copy of the GNU General Public License along
  15. with anontwi; if not, write to the Free Software Foundation, Inc., 51
  16. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. Anontwi: Anonymous Twitter Wave Interface
  18. """
  19. import os, sys, traceback, random
  20. import core.twitter
  21. import core.oauth2 as oauth
  22. import re, urllib2, socket
  23. import core.socks
  24. import HTMLParser
  25. from urllib2 import URLError
  26. from core.encrypt import Cipher, generate_key
  27. from core.twitter import TwitterError
  28. from core.options import AnonTwiOptions
  29. from core.shorter import ShortURLReservations
  30. #from core.webserver import AnonTwiWebserver
  31. try:
  32. from urlparse import parse_qsl
  33. except:
  34. from cgi import parse_qsl
  35. # set to emit debug messages about errors (0 = off).
  36. DEBUG = 0
  37. class anontwi(object):
  38. """
  39. AnonTwi application class
  40. """
  41. def __init__(self):
  42. # init AnonTwi
  43. self.anontwi = []
  44. self.consumer_key = ''
  45. self.consumer_secret = ''
  46. self.access_token_key = ''
  47. self.access_token_secret = ''
  48. self.source_api = ''
  49. self.num_tweets = 1
  50. self.proxy = None
  51. self.isurl = 0
  52. self.search = None
  53. self.timeline = None
  54. self.timelinedm = None
  55. self.timelinef = None
  56. self.nickid = ''
  57. self.save = None
  58. self.savefavs = None
  59. # setting random user-agent and blank referer for connections
  60. self.agents = []
  61. self.agents.append('Mozilla/5.0 (iPhone; U; CPU iOS 2_0 like Mac OS X; en-us)')
  62. self.agents.append('Mozilla/5.0 (Linux; U; Android 0.5; en-us)')
  63. self.agents.append('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)')
  64. self.agents.append('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)')
  65. self.agents.append('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13')
  66. self.agents.append('Opera/9.25 (Windows NT 6.0; U; en)')
  67. self.agents.append('Mozilla/2.02E (Win95; U)')
  68. self.agents.append('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')
  69. self.agents.append('Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)')
  70. self.agents.append('Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (FM Scene 4.6.1)')
  71. self.agents.append('Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729) (Prevx 3.0.5)')
  72. self.agents.append('(Privoxy/1.0)')
  73. self.agents.append('CERN-LineMode/2.15')
  74. self.agents.append('cg-eye interactive')
  75. self.agents.append('China Local Browser 2.6')
  76. self.agents.append('ClariaBot/1.0')
  77. self.agents.append('Comos/0.9_(robot@xyleme.com)')
  78. self.agents.append('Crawler@alexa.com')
  79. self.agents.append('DonutP; Windows98SE')
  80. self.agents.append('Dr.Web (R) online scanner: http://online.drweb.com/')
  81. self.agents.append('Dragonfly File Reader')
  82. self.agents.append('Eurobot/1.0 (http://www.ayell.eu)')
  83. self.agents.append('FARK.com link verifier')
  84. self.agents.append('FavIconizer')
  85. self.agents.append('Feliz - Mixcat Crawler (+http://mixcat.com)')
  86. self.agents.append('TwitterBot (http://www.twitter.com)')
  87. self.user_agent = random.choice(self.agents).strip()
  88. self.request_headers = {'User-Agent': self.user_agent, 'Referer': ''}
  89. # setting random fake geoposition
  90. self.geo = []
  91. self.geo.append('0.000000,0.000000') # pangea starts ;-)
  92. self.geo.append('33.449777,-40.935974')
  93. self.geo.append('82.729312,-51.188507')
  94. self.geo.append('14.826575,-24.697266')
  95. self.geo.append('(-43.592825),146.374855')
  96. self.geo.append('54.334036,-4.438477')
  97. self.geo.append('19.277270,-81.276855')
  98. self.geo.append('(-11.833246),96.824212')
  99. self.geo.append('38.897738,-77.03632')
  100. self.geo.append('38.870601,-77.055727')
  101. self.geo.append('41.902916,12.453389')
  102. self.geo.append('37.826664,-122.423012')
  103. self.geo.append('40.444555,-3.73592')
  104. self.geo.append('62.393096,-145.150442')
  105. self.geo.append('34.0231,84.3617')
  106. self.geo.append('19.573938,-4.463196')
  107. self.geo.append('(-22.917923),23.640747')
  108. self.geo.append('28.455556,-80.527778')
  109. self.geo.append('39.7025,44.3')
  110. self.geo.append('30.958769,88.831787')
  111. self.geo.append('32.676138,-117.157763')
  112. self.geo.append('51.9898,5.8176')
  113. self.geo.append('43.264335,-2.945844')
  114. self.geo.append('40.711841,-74.012986')
  115. self.geo.append('51.563412,-68.997803')
  116. self.geo.append('35.168195,-106.848335')
  117. self.geo.append('44.072363,3.522747')
  118. self.geo.append('37.749510,140.468180')
  119. self.geo.append('16.720385,38.305662')
  120. self.geo.append('13.239945,13.608397')
  121. self.geo.append('(-28.22697),-56.967775')
  122. self.geo.append('8.341953,39.06372')
  123. self.geo.append('25.740529,49.764404')
  124. self.geo.append('31.868957,35.211325')
  125. self.geo.append('32.097918,34.810345')
  126. self.geo.append('(-44.496505),-69.000549')
  127. self.geo.append('6.256122,-75.630636')
  128. self.geo.append('29.017748,-112.393799')
  129. self.geo.append('41.808781,-72.649244')
  130. self.geo.append('67.187,-101.341553')
  131. self.geo.append('23.775291,10.193481')
  132. self.geo.append('28.623104,82.999878')
  133. self.geo.append('44.801327,100.694733')
  134. self.geo.append('55.699743,37.611777')
  135. self.geo.append('42.382894,77.28447')
  136. self.geo.append('57.280527,-4.482622')
  137. self.geo.append('27.985648,86.923649')
  138. self.geo.append('39.913791,116.392191')
  139. self.geo.append('41.403737,2.173555')
  140. self.geo.append('37.971618,23.726893')
  141. self.geo.append('29.975939,31.130404')
  142. self.geo.append('51.176599,-1.826048')
  143. self.geo.append('(-14.725285),-75.151978')
  144. self.geo.append('48.865724,2.319070')
  145. self.geo.append('48.874362,2.294501')
  146. self.geo.append('48.861022222222,2.335825')
  147. self.geo.append('39.466581,-0.376314')
  148. self.geo.append('51.39294721838891,30.097381701104')
  149. self.geo.append('55.754186,37.618475')
  150. self.geo.append('34.39708129807727,132.4436864109491')
  151. self.geo.append('32.73333333333333,129.8666666666667')
  152. self.geo.append('33.304331,44.408380')
  153. self.geo.append('(-3.109128),37.366866')
  154. self.geo.append('51.097251,1.156139')
  155. self.geo.append('48.852870,2.349465')
  156. self.geo.append('(-34.603640),-58.381552')
  157. self.geo.append('41.878593,-87.635853')
  158. self.geo.append('51.500462,-0.177262')
  159. self.geo.append('41.902277,12.455245')
  160. self.geo.append('55.751982,37.616007')
  161. self.geo.append('27.17461,78.0447')
  162. self.geo.append('(-25.413609),-54.586945')
  163. self.geo.append('(-27.493629),-56.730309')
  164. self.geo.append('(-73.03408598119988),-50.47799897195181')
  165. self.geo.append('20.989825,-11.252160')
  166. self.geo.append('(-32.6563109388),-70.0027805163')
  167. self.geo.append('(-27.11266944),-109.3469139')
  168. self.geo.append('(-0.329588),-90.681152')
  169. self.geoposition = random.choice(self.geo).strip()
  170. # take consumer and token: secrets and keys
  171. from config import APItokens
  172. for token in APItokens:
  173. self.consumer_key = token['consumer_key']
  174. self.consumer_secret = token['consumer_secret']
  175. # take source api
  176. from config import APIsources
  177. for source in APIsources:
  178. self.source_api = source['source_api']
  179. self.set_oauth_urls()
  180. def set_oauth_urls(self):
  181. self.request_token_url = 'https://' + self.source_api + '/oauth/request_token'
  182. self.access_token_url = 'https://' + self.source_api + '/oauth/access_token'
  183. self.authorization_url = 'https://' + self.source_api + '/oauth/authorize'
  184. self.signin_url = 'https://' + self.source_api + '/oauth/authenticate'
  185. def set_options(self, options):
  186. """
  187. Set anontwi options
  188. """
  189. self.options = options
  190. def create_options(self, args=None):
  191. """
  192. Create the program options for OptionParser.
  193. """
  194. self.optionParser = AnonTwiOptions()
  195. self.options = self.optionParser.get_options(args)
  196. if not self.options:
  197. return False
  198. return self.options
  199. def try_running(self, func, error, args=None):
  200. """
  201. Try running a function and print some error if it fails and exists with
  202. a fatal error.
  203. """
  204. options = self.options
  205. args = args or []
  206. try:
  207. return func(*args)
  208. except Exception as e:
  209. if options.timeline or options.timelinedm or options.save:
  210. print("[Error] - Something wrong or this user doesn't exists!!. Aborting..."), "\n"
  211. if options.gtk:
  212. return
  213. else:
  214. sys.exit(2)
  215. if options.timelinef:
  216. print("[Error] - Something wrong fetching friend's timeline. Aborting..."), "\n"
  217. if options.gtk:
  218. return
  219. else:
  220. sys.exit(2)
  221. if options.tweet:
  222. print "\n[Error] - Something wrong sending your tweet. ",e,"\n\nRemember that text must be less than or equal to 140 characters.\nConsider using --wave to split it on different blocks if has more than 1 wave. Aborting... \n"
  223. if options.gtk:
  224. return
  225. else:
  226. sys.exit(2)
  227. if options.rmtweet:
  228. print("\n[Error] - Something wrong removing tweet. Check that you are using a correct ID. Aborting..."), "\n"
  229. if options.gtk:
  230. return
  231. else:
  232. sys.exit(2)
  233. if options.rmdm:
  234. print("\n[Error] - Something wrong removing direct message. Check that you are using a correct ID. Aborting..."), "\n"
  235. if options.gtk:
  236. return
  237. else:
  238. sys.exit(2)
  239. if options.retweet:
  240. print("\n[Error] - Something wrong with tweet's ID!!. Aborting..."), "\n"
  241. if options.gtk:
  242. return
  243. else:
  244. sys.exit(2)
  245. if options.friend:
  246. print"\n[Error] - Something wrong creating your friendship. Aborting...", "\n"
  247. if options.gtk:
  248. return
  249. else:
  250. sys.exit(2)
  251. #if options.massfriend:
  252. # print"\nSomething wrong with massive friendships. Aborting...", "\n"
  253. # sys.exit(2)
  254. if options.dfriend:
  255. print "\n[Error] - Something wrong destroying your friendship. Aborting...", "\n"
  256. if options.gtk:
  257. return
  258. else:
  259. sys.exit(2)
  260. if options.mentions:
  261. print("\n[Error] - Something wrong fetching your mentions. Aborting..."), "\n"
  262. if options.gtk:
  263. return
  264. else:
  265. sys.exit(2)
  266. if options.block:
  267. print("\n[Error] - Something wrong blocking user "), options.block, e, (" Aborting...\n")
  268. if options.gtk:
  269. return
  270. else:
  271. sys.exit(2)
  272. if options.unblock:
  273. print("\n[Error] - Something wrong unblocking user "), options.unblock,e, (" Aborting...\n")
  274. if options.gtk:
  275. return
  276. else:
  277. sys.exit(2)
  278. else:
  279. print(error, "error")
  280. if DEBUG:
  281. traceback.print_exc()
  282. def get_messages(self):
  283. """
  284. Get messages to send (Tweet, Image or DM)
  285. """
  286. messages = []
  287. options = self.options
  288. p = self.optionParser
  289. if options.tweet:
  290. if options.dm:
  291. print('='*75)
  292. print(str(p.version))
  293. print('='*75)
  294. print("Starting to send your DM (direct message)... :)")
  295. print('='*75)
  296. elif options.wave:
  297. print('='*75)
  298. print(str(p.version))
  299. print('='*75)
  300. print("Starting to send your waves... :)")
  301. print('='*75)
  302. else:
  303. print('='*75)
  304. print(str(p.version))
  305. print('='*75)
  306. print("Starting to send your tweet... :)")
  307. print('='*75)
  308. messages = [options.tweet]
  309. #if options.image:
  310. # print('='*75)
  311. # print(str(p.version))
  312. # print('='*75)
  313. # print("Starting to send your image... :)")
  314. # print('='*75)
  315. # messages = [options.image]
  316. #if options.friend and not (options.tweet or options.image):
  317. if options.friend and not options.tweet:
  318. print('='*75)
  319. print(str(p.version))
  320. print('='*75)
  321. print "Creating friendship with:", options.friend, " :)"
  322. print('='*75)
  323. elif options.friend:
  324. print "Creating friendship:", options.friend
  325. print('='*75)
  326. #if options.dfriend and not (options.tweet or options.image):
  327. if options.dfriend and not options.tweet:
  328. print('='*75)
  329. print(str(p.version))
  330. print('='*75)
  331. print "Destroying friendship with:", options.dfriend, " :)"
  332. print('='*75)
  333. elif options.dfriend:
  334. print "Destroying friendship:", options.dfriend
  335. print('='*75)
  336. if options.decaes:
  337. print('='*75)
  338. print(str(p.version))
  339. print('='*75)
  340. print "Decrypting message... :)"
  341. print('='*75)
  342. if options.block:
  343. print('='*75)
  344. print(str(p.version))
  345. print('='*75)
  346. print "Blocking user:", options.block, " :)"
  347. print('='*75)
  348. if options.unblock:
  349. print('='*75)
  350. print(str(p.version))
  351. print('='*75)
  352. print "Unblocking user::", options.unblock, " :)"
  353. print('='*75)
  354. if options.favorite:
  355. print('='*75)
  356. print(str(p.version))
  357. print('='*75)
  358. print "Creating favorite... :)"
  359. print('='*75)
  360. if options.unfavorite:
  361. print('='*75)
  362. print(str(p.version))
  363. print('='*75)
  364. print "Destroying favorite... :)"
  365. print('='*75)
  366. return messages
  367. def get_tweetids(self):
  368. """
  369. Get messages to send (Tweet, Image or DM)
  370. """
  371. tweetids = []
  372. options = self.options
  373. p = self.optionParser
  374. if options.retweet:
  375. print('='*75)
  376. print(str(p.version))
  377. print('='*75)
  378. print("Starting to reTweet... :)")
  379. print('='*75)
  380. elif options.rmtweet:
  381. print('='*75)
  382. print(str(p.version))
  383. print('='*75)
  384. print("Starting to remove tweet... :)")
  385. print('='*75)
  386. elif options.rmdm:
  387. print('='*75)
  388. print(str(p.version))
  389. print('='*75)
  390. print("Starting to remove direct message... :)")
  391. print('='*75)
  392. return tweetids
  393. def request_url(self,
  394. consumer_key = '',
  395. consumer_secret = '',
  396. source_api = '',
  397. gtk = False):
  398. """
  399. Request Access Tokens
  400. """
  401. options = self.options
  402. proxy = options.proxy
  403. eprint = sys.stderr.write
  404. proxy_info = None
  405. if proxy is not None:
  406. try:
  407. match = re.finditer(":",proxy)
  408. positionlist = []
  409. for m in match:
  410. positionlist.append(m.start())
  411. pos1 = positionlist[0]
  412. pos2 = positionlist[1]
  413. host = proxy[pos1+3:pos2]
  414. slen = len(proxy)
  415. port = proxy[pos2+1:slen]
  416. proxy_info = core.socks.setdefaultproxy(core.socks.PROXY_TYPE_HTTP, host, int(port))
  417. socket.socket = core.socks.socksocket
  418. except IndexError:
  419. eprint ("\n[Error] - Proxy is malformed. For example, to launch with TOR use: --proxy 'http://127.0.0.1:8118'")
  420. eprint ("\nAborting...\n")
  421. if options.gtk:
  422. return
  423. else:
  424. sys.exit(2)
  425. except ValueError:
  426. eprint ("[Error] - Proxy is malformed. For example, to launch with TOR use: --proxy 'http://127.0.0.1:8118'")
  427. eprint ("\nAborting...\n")
  428. if options.gtk:
  429. return
  430. else:
  431. sys.exit(2)
  432. if gtk:
  433. self.consumer_key = consumer_key
  434. self.consumer_secret = consumer_secret
  435. self.source_api = source_api
  436. signature_method_hmac_sha1 = oauth.SignatureMethod_HMAC_SHA1()
  437. oauth_consumer = oauth.Consumer(key = self.consumer_key, secret = self.consumer_secret)
  438. #if self.source_api == "identi.ca/api":
  439. # self.request_token_url = #"https://identi.ca/api/oauth/request_token?oauth_callback=http://anontwi.03c8.net"
  440. self.request_token_url = self.request_token_url + '?oauth_callback=oob'
  441. oauth_client = oauth.Client(oauth_consumer, proxy_info = proxy_info)
  442. eprint ('\n')
  443. if options.rgb:
  444. eprint ('Requesting \033[1;36mtemporal\033[1;m tokens...')
  445. else:
  446. eprint ('Requesting temporal tokens...')
  447. eprint ('\n\n')
  448. try:
  449. resp, content = oauth_client.request(self.request_token_url, 'GET', headers=self.request_headers)
  450. except:
  451. if options.rgb:
  452. eprint ("\033[1;31mConnection refused!\033[1;m\n\n")
  453. else:
  454. eprint ("Connection refused!\n\n")
  455. if options.gtk:
  456. return
  457. else:
  458. sys.exit(2)
  459. if resp['status'] != '200':
  460. eprint ('\n')
  461. eprint ('Invalid response!!. http code is: %s' % resp['status']+ "\n")
  462. eprint ('----------------'+ "\n")
  463. if options.rgb:
  464. eprint ('Review \033[1;31mconfig.py\033[1;m file to see if your API consumer and token values (secret and key) are correct')
  465. else:
  466. eprint ('Review config.py file to see if your API consumer and token values (secret and key) are correct' + "\n")
  467. eprint ('If you are using a proxy, check that is working correctly'+ "\n")
  468. eprint ('\n')
  469. if options.gtk:
  470. return
  471. else:
  472. sys.exit(2)
  473. else:
  474. request_token = dict(parse_qsl(content))
  475. eprint ('Please visit this page and retrieve the pincode to be used')
  476. eprint ('\n')
  477. eprint ('in the next step to obtaining an Authentication Token:')
  478. eprint ('\n\n')
  479. if not gtk:
  480. if options.rgb:
  481. eprint ('\033[1;34m%s?oauth_token=%s\033[1;m' % (self.authorization_url, request_token['oauth_token']))
  482. else:
  483. eprint ('%s?oauth_token=%s' % (self.authorization_url, request_token['oauth_token']))
  484. return [request_token['oauth_token'],
  485. request_token['oauth_token_secret']]
  486. else:
  487. return [self.authorization_url + '?oauth_token=' + request_token['oauth_token'],
  488. request_token['oauth_token'],
  489. request_token['oauth_token_secret']]
  490. def insert_pincode(self,
  491. _oauth_token,
  492. _oauth_token_secret,
  493. _consumer_key,
  494. _consumer_secret,
  495. source_api = '',
  496. _pin = "",
  497. gtk = False):
  498. consumer_key = _consumer_key
  499. consumer_secret = _consumer_secret
  500. oauth_token = _oauth_token
  501. oauth_token_secret = _oauth_token_secret
  502. #proxy setup - copy from request_url
  503. options = self.options
  504. proxy = options.proxy
  505. eprint = sys.stderr.write
  506. proxy_info = None
  507. if proxy is not None:
  508. try:
  509. match = re.finditer(":",proxy)
  510. positionlist = []
  511. for m in match:
  512. positionlist.append(m.start())
  513. pos1 = positionlist[0]
  514. pos2 = positionlist[1]
  515. host = proxy[pos1+3:pos2]
  516. slen = len(proxy)
  517. port = proxy[pos2+1:slen]
  518. proxy_info = core.socks.setdefaultproxy(core.socks.PROXY_TYPE_HTTP, host, int(port))
  519. socket.socket = core.socks.socksocket
  520. except IndexError:
  521. eprint ("\n[Error] - Proxy is malformed. For example, to launch with TOR use: --proxy 'http://127.0.0.1:8118'")
  522. eprint ("\nAborting...\n")
  523. if options.gtk:
  524. return
  525. else:
  526. sys.exit(2)
  527. except ValueError:
  528. eprint ("[Error] - Proxy is malformed. For example, to launch with TOR use: --proxy 'http://127.0.0.1:8118'")
  529. eprint ("\nAborting...\n")
  530. if options.gtk:
  531. return
  532. else:
  533. sys.exit(2)
  534. eprint ("\n\n")
  535. if self.source_api == "api.twitter.com":
  536. if gtk:
  537. pincode = _pin
  538. else:
  539. eprint ("Pincode? ")
  540. pincode = raw_input ()
  541. token = oauth.Token(oauth_token, oauth_token_secret)
  542. token.set_verifier(pincode)
  543. else:
  544. if gtk:
  545. pincode = _pin
  546. else:
  547. eprint ("Pincode? ")
  548. pincode = raw_input ()
  549. token = oauth.Token(oauth_token, oauth_token_secret)
  550. token.set_verifier(pincode)
  551. eprint ('\n')
  552. eprint ('Generating and signing request for an access token...')
  553. eprint ('\n\n')
  554. oauth_consumer = oauth.Consumer(key = self.consumer_key, secret = self.consumer_secret)
  555. oauth_client = oauth.Client(oauth_consumer, token, proxy_info = proxy_info)
  556. try:
  557. resp, content = oauth_client.request(self.access_token_url, method='POST', body='oauth_verifier=%s' % pincode, headers=self.request_headers)
  558. except:
  559. if options.rgb:
  560. eprint ("\033[1;31mConnection refused!\033[1;m\n\n")
  561. else:
  562. eprint ("Connection refused!\n\n")
  563. if options.gtk:
  564. return
  565. else:
  566. sys.exit(2)
  567. access_token = dict(parse_qsl(content))
  568. if resp['status'] != '200':
  569. eprint ('The request for Tokens did not succeed: %s' % resp['status'])
  570. eprint ('\n\n')
  571. else:
  572. if options.rgb:
  573. eprint ('Your Access Token key: \033[1;31m%s\033[1;m' % access_token['oauth_token'])
  574. eprint ('\n')
  575. eprint (' Access Token secret: \033[1;31m%s\033[1;m' % access_token['oauth_token_secret'])
  576. eprint ('\n')
  577. else:
  578. eprint ('Your Access Token key: %s' % access_token['oauth_token'])
  579. eprint ('\n')
  580. eprint (' Access Token secret: %s' % access_token['oauth_token_secret'])
  581. eprint ('\n')
  582. access_token_key = access_token['oauth_token']
  583. access_token_secret = access_token['oauth_token_secret']
  584. eprint ('\n')
  585. eprint ('Trying to export tokens like environment variables...')
  586. eprint ('\n\n')
  587. eprint (' + Unix/MacOS: ')
  588. eprint ('\n')
  589. eprint (' - If you launched: "eval $(python anontwi --tokens)" you can START to use it!!')
  590. eprint ('\n')
  591. eprint (' - If you launched: "python anontwi --tokens" COPY next EXPORT lines to your shell:')
  592. eprint ('\n\n')
  593. eprint ('-------------------------------------------------------------------------')
  594. eprint ('\n')
  595. if options.rgb:
  596. print(' \033[1;31mexport ANONTWI_TOKEN_KEY=' + access_token_key + "\033[1;m")
  597. print(' \033[1;31mexport ANONTWI_TOKEN_SECRET=' + access_token_secret + "\033[1;m")
  598. else:
  599. print(' export ANONTWI_TOKEN_KEY=' + access_token_key)
  600. print(' export ANONTWI_TOKEN_SECRET=' + access_token_secret)
  601. eprint ('-------------------------------------------------------------------------')
  602. eprint ('\n\n')
  603. eprint (' + Windows: ')
  604. eprint ('\n')
  605. eprint (' - COPY next EXPORT lines to your shell:')
  606. eprint ('\n\n')
  607. eprint ('-------------------------------------------------------------------------')
  608. eprint ('\n')
  609. if options.rgb:
  610. print(' \033[1;31mSET ANONTWI_TOKEN_KEY=' + access_token_key + "\033[1;m")
  611. print(' \033[1;31mSET ANONTWI_TOKEN_SECRET=' + access_token_secret + "\033[1;m")
  612. else:
  613. print(' SET ANONTWI_TOKEN_KEY=' + access_token_key)
  614. print(' SET ANONTWI_TOKEN_SECRET=' + access_token_secret)
  615. eprint ('-------------------------------------------------------------------------')
  616. eprint ('\n\n')
  617. eprint ('Is you save these tokens like environment variables on your system')
  618. eprint ('\n')
  619. eprint ('You can use the tool directly without entering them every time')
  620. eprint ('\n')
  621. eprint ('Remember that you can request new temporal tokens again if is needed')
  622. eprint ('\n')
  623. if options.rgb:
  624. eprint ('So at the end, time to \033[1;33menjoy\033[1;m #AnonTwi ;)')
  625. else:
  626. eprint ('So at the end, time to enjoy #AnonTwi ;)')
  627. eprint ('\n\n')
  628. return access_token_key, access_token_secret
  629. def get_env_tokens(self):
  630. """
  631. Get temporal access token key and secret from env, or go to command argvs
  632. """
  633. options = self.options
  634. try:
  635. self.access_token_key = os.environ['ANONTWI_TOKEN_KEY']
  636. self.access_token_secret = os.environ['ANONTWI_TOKEN_SECRET']
  637. except:
  638. (self.access_token_key, self.access_token_secret) = self.get_access_token(options)
  639. def unicoding(self, message):
  640. message = message.decode("utf-8")
  641. return message
  642. def send_dm(self, message, dm):
  643. """
  644. Send Direct Message (DM)
  645. """
  646. options = self.options
  647. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  648. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  649. try:
  650. status = api.PostDirectMessage(message, dm)
  651. except URLError as u:
  652. print "[Error] - ",u.reason.strerror, "\n"
  653. if options.gtk:
  654. return
  655. else:
  656. sys.exit(2)
  657. except TwitterError as t:
  658. try:
  659. print "[Error] - ",t, "\n"
  660. if options.gtk:
  661. return
  662. else:
  663. sys.exit(2)
  664. except Exception:
  665. print "Oops! It seems that you've said that\n"
  666. if options.gtk:
  667. return
  668. else:
  669. sys.exit(2)
  670. def send_tweet(self, message, reply, lat, long):
  671. """
  672. Send messages
  673. """
  674. options = self.options
  675. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  676. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  677. try:
  678. for m in message:
  679. message = self.unicoding(m)
  680. status = api.PostUpdate(status=message, in_reply_to_status_id=reply, latitude=lat, longitude=long)
  681. except URLError as u:
  682. print "\n[Error] - ",u.reason.strerror, "\n"
  683. if options.gtk:
  684. return
  685. else:
  686. sys.exit(2)
  687. def send_wave(self, message, reply, lat, long):
  688. """
  689. Send waves of messages
  690. """
  691. options = self.options
  692. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  693. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  694. try:
  695. for m in message:
  696. message = self.unicoding(m)
  697. status = api.PostUpdates(status=message, in_reply_to_status_id=reply, latitude=lat, longitude=long)
  698. except URLError as u:
  699. print "\n[Error] - ",u.reason.strerror, "\n"
  700. if options.gtk:
  701. return
  702. else:
  703. sys.exit(2)
  704. except TwitterError as t:
  705. print "\n[Error] - ",t, "\n"
  706. if options.gtk:
  707. return
  708. else:
  709. sys.exit(2)
  710. def remove_tweet(self):
  711. """
  712. Remove tweet by id
  713. """
  714. options = self.options
  715. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  716. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  717. try:
  718. status = api.DestroyStatus(options.rmtweet)
  719. except URLError as u:
  720. print "\n[Error] - ",u.reason.strerror, "\n"
  721. if options.gtk:
  722. return
  723. else:
  724. sys.exit(2)
  725. except TwitterError as t:
  726. print "\n[Error] - ",t, "\n"
  727. if options.gtk:
  728. return
  729. else:
  730. sys.exit(2)
  731. def remove_dm(self):
  732. """
  733. Remove direct message by id
  734. """
  735. options = self.options
  736. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  737. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  738. try:
  739. status = api.DestroyDirectMessage(options.rmdm)
  740. except URLError as u:
  741. print "\n[Error] - ",u.reason.strerror, "\n"
  742. if options.gtk:
  743. return
  744. else:
  745. sys.exit(2)
  746. except TwitterError as t:
  747. print "\n[Error] - ",t, "\n"
  748. if options.gtk:
  749. return
  750. else:
  751. sys.exit(2)
  752. def send_retweet(self):
  753. """
  754. Send retweets of users by id
  755. """
  756. options = self.options
  757. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  758. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  759. try:
  760. id = int(options.retweet)
  761. status = api.PostRetweet(id)
  762. except URLError as u:
  763. print "\n[Error] - ",u.reason.strerror, "\n"
  764. if options.gtk:
  765. return
  766. else:
  767. sys.exit(2)
  768. except TwitterError as t:
  769. print "\n[Error] - ",t, "\n"
  770. if options.gtk:
  771. return
  772. else:
  773. sys.exit(2)
  774. # def send_image(self, message, image):
  775. # """
  776. # Send image on Twitpic
  777. # """
  778. # options.self.options
  779. # tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  780. # api = twitpic.TwitPicOAuthClient(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  781. # try:
  782. # status = api.create("upload", message, image)
  783. # print(status)
  784. # except URLError as u:
  785. # print "[Error] - ",u.reason.strerror, "\n"
  786. # sys.exit(2)
  787. # except TwitterError as t:
  788. # print "[Error] - ",t, "\n"
  789. # sys.exit(2)
  790. def search_messages(self):
  791. """
  792. Search messages
  793. """
  794. options = self.options
  795. search = options.search
  796. try:
  797. num = options.args[0]
  798. except:
  799. num = 10
  800. words = options.search.split()
  801. if len(words) is 2:
  802. search = words[0]
  803. num = words[1]
  804. else:
  805. search = options.search
  806. try:
  807. if int(num) <= 0:
  808. print "[Error] - Number of ocurrences must be an integer greater than zero. (ex: --ts 'AnonTwi 5')\n"
  809. print "Aborting ....\n"
  810. if options.gtk:
  811. return
  812. else:
  813. sys.exit(2)
  814. except ValueError:
  815. print "[Error] - Number of ocurrences must be an integer greater than zero. (ex: --ts 'AnonTwi 3')\n"
  816. print "Aborting ....\n"
  817. if options.gtk:
  818. return
  819. else:
  820. sys.exit(2)
  821. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  822. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  823. status = api.GetSearch(search, count=num)
  824. return status
  825. def search_topics(self):
  826. """
  827. Search trending topics
  828. """
  829. options = self.options
  830. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  831. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  832. status = api.GetTrendsCurrent()
  833. return status
  834. def save_timeline(self):
  835. """
  836. Save a number of tweets of a user timeline
  837. """
  838. options = self.options
  839. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  840. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  841. count = 15
  842. user = ""
  843. words = options.save.split()
  844. if len(words) is 2:
  845. user = words[0]
  846. count = words[1]
  847. else:
  848. word = options.save
  849. try:
  850. count = int(word)
  851. except:
  852. user = word
  853. if self.source_api != 'api.twitter.com':
  854. import string
  855. user = string.replace(user, "@", "")
  856. try:
  857. if self.source_api == "api.twitter.com":
  858. status = api.GetUserTimeline(user, count)
  859. else:
  860. status = api.GetUserTimeline(screen_name=user, count=count)
  861. return status, count
  862. except URLError as u:
  863. print "\n[Error] - ",u.reason.strerror, "\n"
  864. if options.gtk:
  865. return
  866. else:
  867. sys.exit(2)
  868. except TwitterError as t:
  869. print "\n[Error] - ",t, "\n"
  870. if options.gtk:
  871. return
  872. else:
  873. sys.exit(2)
  874. def show_timeline(self):
  875. """
  876. Show a number of tweets of a user timeline
  877. """
  878. options = self.options
  879. try:
  880. num = options.args[0]
  881. except:
  882. num = 10
  883. words = options.timeline.split()
  884. if len(words) is 2:
  885. user = words[0]
  886. num = words[1]
  887. else:
  888. user = options.timeline
  889. if self.source_api != "api.twitter.com":
  890. if user[0:1] == "@":
  891. user = user[1:len(user)]
  892. try:
  893. if int(num) <= 0:
  894. print "[Error] - Number of ocurrences must be an integer greater than zero. (ex: --tu '@user 5')\n"
  895. print "Aborting ....\n"
  896. if options.gtk:
  897. return
  898. else:
  899. sys.exit(2)
  900. except ValueError:
  901. print "[Error] - Number of ocurrences must be an integer greater than zero. (ex: --tu '@user 5')\n"
  902. print "Aborting ....\n"
  903. if options.gtk:
  904. return
  905. else:
  906. sys.exit(2)
  907. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  908. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  909. try:
  910. if self.source_api == "api.twitter.com":
  911. status = api.GetUserTimeline(user, count=num, include_rts=1)
  912. else:
  913. status = api.GetUserTimeline(screen_name=user, count=num, include_rts=1)
  914. except TwitterError as t:
  915. print "[Error] - ",t,"\n"
  916. if options.gtk:
  917. return
  918. else:
  919. sys.exit(2)
  920. return status
  921. def show_timelinedm(self):
  922. """
  923. Show a number of DMs
  924. """
  925. options = self.options
  926. try:
  927. dm = options.timelinedm
  928. try:
  929. if int(dm) <= 0:
  930. print "[Error] - Number of ocurrences must be an integer greater than zero. (ex: --td '5')\n"
  931. print "Aborting ....\n"
  932. if options.gtk:
  933. return
  934. else:
  935. sys.exit(2)
  936. except Exception as e:
  937. print "[Error] - Number of ocurrences must be an integer greater than zero. (ex: --td '3')\n"
  938. print "Aborting ....\n"
  939. if options.gtk:
  940. return
  941. else:
  942. sys.exit(2)
  943. except Exception:
  944. dm = 10
  945. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  946. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  947. try:
  948. status = api.GetDirectMessages()
  949. except TwitterError as t:
  950. print "[Error] - ",t,"\n"
  951. if options.gtk:
  952. return
  953. else:
  954. sys.exit(2)
  955. return status, dm
  956. def show_timeline_friends(self):
  957. """
  958. Show a number of tweets of your friends
  959. """
  960. options = self.options
  961. try:
  962. num = options.timelinef
  963. except:
  964. num = 10
  965. try:
  966. if int(num) <= 0:
  967. print "[Error] - Number of ocurrences must be an integer greater than zero. (ex: --tf '5')\n"
  968. print "Aborting ....\n"
  969. if options.gtk:
  970. return
  971. else:
  972. sys.exit(2)
  973. except ValueError:
  974. print "[Error] - Number of ocurrences must be an integer greater than zero. (ex: --tf '3')\n"
  975. print "Aborting ....\n"
  976. if options.gtk:
  977. return
  978. else:
  979. sys.exit(2)
  980. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  981. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  982. try:
  983. status = api.GetHomeTimeline(count=num)
  984. except TwitterError as t:
  985. if options.gtk:
  986. return
  987. else:
  988. print "[Error] - ",t,"\n"
  989. if options.gtk:
  990. return
  991. else:
  992. sys.exit(2)
  993. return status, num
  994. def show_mentions(self):
  995. """
  996. Show a number of mentions about you
  997. """
  998. options = self.options
  999. try:
  1000. mention = options.mentions
  1001. try:
  1002. if int(mention) <= 0:
  1003. print "[Error] - Number of ocurrences must be an integer greater than zero. (ex: --me '5')\n"
  1004. print "Aborting ....\n"
  1005. if options.gtk:
  1006. return
  1007. else:
  1008. sys.exit(2)
  1009. except Exception as e:
  1010. print "[Error] - Number of ocurrences must be an integer greater than zero. (ex: --me '3')\n"
  1011. print "Aborting ....\n"
  1012. if options.gtk:
  1013. return
  1014. else:
  1015. sys.exit(2)
  1016. except Exception:
  1017. mention = 10
  1018. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1019. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1020. try:
  1021. status = api.GetMentions()
  1022. except TwitterError as t:
  1023. print "[Error] - ",t,"\n"
  1024. if options.gtk:
  1025. return
  1026. else:
  1027. sys.exit(2)
  1028. return status, mention
  1029. def set_friend(self):
  1030. """
  1031. Create a friendship with a user
  1032. """
  1033. options = self.options
  1034. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1035. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1036. #if options.massfriend:
  1037. # try:
  1038. # f = open(options.massfriend)
  1039. # friends = f.readlines()
  1040. # friends = [ line.replace('\n','') for line in friends ]
  1041. # f.close()
  1042. # except:
  1043. # import os.path
  1044. # if os.path.exists(options.massfriend) == True:
  1045. # self.report('\nThere is some errors opening the file: ', options.massfriend, "\n")
  1046. # else:
  1047. # self.report('\nThe file: ', options.massfriend, " doesn't exist!!\n")
  1048. # status = api.CreateFriendship(options.massfriend)
  1049. #else:
  1050. status = api.CreateFriendship(options.friend)
  1051. return status
  1052. def remove_friend(self):
  1053. """
  1054. Destroy a friendship with a user
  1055. """
  1056. options = self.options
  1057. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1058. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1059. status = api.DestroyFriendship(options.dfriend)
  1060. return status
  1061. def create_block(self):
  1062. """
  1063. Create block with a user
  1064. """
  1065. options = self.options
  1066. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1067. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1068. user = api.CreateBlock(screen_name=options.block)
  1069. if user.id is None:
  1070. print("\n[Error] - Something wrong or this user doesn't exists!!. Aborting..."), "\n"
  1071. if options.gtk:
  1072. return
  1073. else:
  1074. sys.exit(2)
  1075. def destroy_block(self):
  1076. """
  1077. Destroy blockwith a user
  1078. """
  1079. options = self.options
  1080. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1081. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1082. user = api.DestroyBlock(screen_name=options.unblock)
  1083. if user.id is None:
  1084. print("\n[Error] - Something wrong or this user doesn't exists!!. Aborting..."), "\n"
  1085. if options.gtk:
  1086. return
  1087. else:
  1088. sys.exit(2)
  1089. def get_access_token(self, options):
  1090. """
  1091. Get access token key and secret from argvs
  1092. """
  1093. try:
  1094. access_token_key = options.args[0]
  1095. except:
  1096. if options.rgb:
  1097. print "[Error] - you must provide a valid access '\033[1;31mtoken key\033[1;m'\n"
  1098. print "[Info] - to use tool, entering tokens every time: ./anontwi [OPTIONS] '\033[1;31mtoken key\033[1;m' 'token secret'"
  1099. print "[Info] - to use tool, \033[1;32mWITHOUT\033[1;m entering tokens every time: \033[1;32m./anontwi --tokens\033[1;m"
  1100. print "\nAborting...\n"
  1101. else:
  1102. print "[Error] - you must provide a valid access 'token key'\n"
  1103. print "[Info] - use tool, entering tokens every time: ./anontwi [OPTIONS] 'token key' 'token secret'"
  1104. print "[Info] - use tool, WITHOUT entering tokens every time: ./anontwi --tokens"
  1105. print "\nAborting...\n"
  1106. if options.gtk:
  1107. return
  1108. else:
  1109. sys.exit(2)
  1110. try:
  1111. access_token_secret = options.args[1]
  1112. except:
  1113. if options.rgb:
  1114. print "[Error] - you must provide a valid access '\033[1;31mtoken secret\033[1;m'\n"
  1115. print "[Info] - use tool entering tokens every time: ./anontwi [OPTIONS] 'token key' '\033[1;31mtoken secret\033[1;m'"
  1116. print "[Info] - use tool \033[1;32mWITHOUT\033[1;m entering tokens every time: \033[1;32m./anontwi --tokens\033[1;m"
  1117. print "\nAborting...\n"
  1118. else:
  1119. print "[Error] - you must provide a valid access 'token secret'\n"
  1120. print "[Info] - use tool entering tokens every time: ./anontwi [OPTIONS] 'token key' 'token secret'"
  1121. print "[Info] - use tool WITHOUT entering tokens every time: ./anontwi --tokens"
  1122. print "\nAborting...\n"
  1123. if options.gtk:
  1124. return
  1125. else:
  1126. sys.exit(2)
  1127. return (access_token_key, access_token_secret)
  1128. def get_location(self):
  1129. """
  1130. Get latitude and longitude parameters
  1131. """
  1132. options = self.options
  1133. try:
  1134. geo = options.args[0]
  1135. try:
  1136. words = geo.split(',')
  1137. lat = words[0]
  1138. # remove parser branches and blank spaces on input parameters
  1139. lat = lat.replace("(", "")
  1140. lat = lat.replace(")", "")
  1141. lat = lat.replace(" ", "")
  1142. long = words[1]
  1143. long = long.replace("(", "")
  1144. long = long.replace(")", "")
  1145. long = long.replace(" ", "")
  1146. except Exception as e:
  1147. print "[Error] - You must provide correct latitude and longitude (ex: --gps '(-43.5209),146.6015')"
  1148. print " If you dont put any (--gps), coordenates will be random :)\n"
  1149. print "[Error] - Sending message process has being aborted!\n"
  1150. if options.gtk:
  1151. return
  1152. else:
  1153. sys.exit(2)
  1154. except Exception:
  1155. words = self.geoposition.split(',')
  1156. lat = words[0]
  1157. long = words[1]
  1158. return (lat, long)
  1159. #def set_via(self):
  1160. # """
  1161. # Set 'source' value to be displayed on the website
  1162. # """
  1163. # options = self.options
  1164. # tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1165. # api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1166. # status = api.SetSource(options.via)
  1167. def encrypt(self, messages, key):
  1168. """
  1169. Encrypt messages
  1170. """
  1171. options = self.options
  1172. if key is None:
  1173. if options.rgb:
  1174. print"\n\033[1;31m[Error] - PIN/Key option (--pin) is required!\033[1;m"
  1175. else:
  1176. print"\n[Error] - PIN/Key option (--pin) is required!"
  1177. print "\nAborting...\n"
  1178. if options.gtk:
  1179. return
  1180. else:
  1181. sys.exit(2)
  1182. else:
  1183. m_encrypt = set()
  1184. for m in messages:
  1185. e = Cipher(key, m)
  1186. m_enc = e.encrypt()
  1187. m_encrypt.add(m_enc)
  1188. return m_encrypt
  1189. def decrypt(self, messages, key):
  1190. """
  1191. Decrypt messages
  1192. """
  1193. options = self.options
  1194. if key is None:
  1195. if options.rgb:
  1196. print "\n\033[1;31m[Error] - PIN/Key option (--pin) is required!\033[1;m"
  1197. else:
  1198. print "\n[Error] - PIN/Key option (--pin) is required!"
  1199. print "\nAborting...\n"
  1200. if options.gtk:
  1201. return
  1202. else:
  1203. sys.exit(2)
  1204. else:
  1205. options = self.options
  1206. # url
  1207. if "https://" in options.decaes:
  1208. match = re.finditer("/", options.decaes)
  1209. positionlist = []
  1210. for m in match:
  1211. positionlist.append(m.start())
  1212. slen = len(options.decaes)
  1213. try:
  1214. pos = positionlist[4]
  1215. id = options.decaes[pos+1:slen]
  1216. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1217. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1218. status = api.GetStatus(id)
  1219. ciphertext = status.text
  1220. except IndexError:
  1221. print "\n[Error] - URL is not valid"
  1222. print "\nAborting...\n"
  1223. if options.gtk:
  1224. return
  1225. else:
  1226. sys.exit(2)
  1227. except TwitterError as t:
  1228. print "\n[Error] - ",t
  1229. print "\nAborting...\n"
  1230. if options.gtk:
  1231. return
  1232. else:
  1233. sys.exit(2)
  1234. # raw_message
  1235. else:
  1236. ciphertext = options.decaes
  1237. key = options.key
  1238. d = Cipher(key, ciphertext)
  1239. plaintext = d.decrypt()
  1240. if plaintext is None:
  1241. print "\n[Error] - PIN key is incorrect or message is corrupted"
  1242. print "\nAborting...\n"
  1243. if options.gtk:
  1244. return
  1245. else:
  1246. sys.exit(2)
  1247. print "\nPlainText:", plaintext, "\n"
  1248. return plaintext
  1249. def suicide(self):
  1250. """
  1251. Remove all possible data and try to close account
  1252. """
  1253. import time
  1254. options = self.options
  1255. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1256. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1257. pag = 1
  1258. status = []
  1259. print "Unfollowing:"
  1260. print "----------------\n"
  1261. #destroy friendship
  1262. try:
  1263. friends = api.GetFriends()
  1264. count = len(friends)
  1265. num = 1
  1266. if friends == []:
  1267. print "No results found.\n"
  1268. for update in friends:
  1269. print "Number of message: [", num, "/", count, "]"
  1270. num = num + 1
  1271. print "ID:", update.id
  1272. print update.screen_name
  1273. status = api.DestroyFriendship(update.id)
  1274. print "\nREMOVED!"
  1275. print "-----------"
  1276. pag = pag + 1
  1277. except TwitterError as t:
  1278. print "[Info] Sleeping for 10 minutes. This is because the API is trying to block you."
  1279. print " Stop this (ctrl+C) and change your IP, if you dont want to wait. ZZzzzzZZzz...\n"
  1280. time.sleep(600) # Sleep for 10 minutes and try again.
  1281. print "Removing Direct Messages:"
  1282. print "--------------------------\n"
  1283. #destroy direct messages
  1284. try:
  1285. status = api.GetDirectMessages(page=pag)
  1286. count = len(status)
  1287. num = 1
  1288. if status == []:
  1289. print "No results found.\n"
  1290. for update in status:
  1291. print "Number of message: [", num, "/", count, "]"
  1292. num = num + 1
  1293. print "ID:", update.id
  1294. print update.text
  1295. print "\nREMOVED!"
  1296. api.DestroyDirectMessage(update.id)
  1297. print "-----------"
  1298. pag = pag + 1
  1299. except TwitterError as t:
  1300. print "[Info] Sleeping for 10 minutes. This is because the API is trying to block you."
  1301. print " Stop this (ctrl+C) and change your IP, if you dont want to wait. ZZzzzzZZzz...\n"
  1302. time.sleep(600) # Sleep for 10 minutes and try again.
  1303. print "Removing Tweets:"
  1304. print "----------------\n"
  1305. #destroy tweets
  1306. try:
  1307. status = api.GetUserTimeline(include_rts=1, page=pag)
  1308. count = len(status)
  1309. num = 1
  1310. if status == []:
  1311. print "No more data.\n"
  1312. for update in status:
  1313. print "Number of message: [", num, "/", count, "]"
  1314. num = num + 1
  1315. print "ID:", update.id
  1316. print update.text
  1317. print "\nREMOVED!"
  1318. api.DestroyStatus(update.id)
  1319. print "-----------"
  1320. pag = pag + 1
  1321. except TwitterError as t:
  1322. print "[Info] Sleeping for 10 minutes. This is because the API is trying to block you."
  1323. print " Stop this (ctrl+C) and change your IP, if you dont want to wait. ZZzzzzZZzz...\n"
  1324. time.sleep(600) # Sleep for 10 minutes and try again.
  1325. print "======", "\n"
  1326. def create_favorite(self):
  1327. """
  1328. Create Favorite
  1329. """
  1330. options = self.options
  1331. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1332. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1333. try:
  1334. api.CreateFavorite(status=options.favorite)
  1335. except URLError as u:
  1336. print "\n[Error] - ",u.reason.strerror, "\n"
  1337. if options.gtk:
  1338. return
  1339. else:
  1340. sys.exit(2)
  1341. except TwitterError as t:
  1342. print "\n[Error] - ",t, "\n"
  1343. if options.gtk:
  1344. return
  1345. else:
  1346. sys.exit(2)
  1347. def destroy_favorite(self):
  1348. """
  1349. Destroy Favorite
  1350. """
  1351. options = self.options
  1352. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1353. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1354. try:
  1355. api.DestroyFavorite(status=options.unfavorite)
  1356. except URLError as u:
  1357. print "\n[Error] - ",u.reason.strerror, "\n"
  1358. if options.gtk:
  1359. return
  1360. else:
  1361. sys.exit(2)
  1362. except TwitterError as t:
  1363. print "\n[Error] - ",t, "\n"
  1364. if options.gtk:
  1365. return
  1366. else:
  1367. sys.exit(2)
  1368. def show_favorites(self):
  1369. """
  1370. Get Favorites
  1371. """
  1372. options = self.options
  1373. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1374. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1375. count = 10
  1376. user = ""
  1377. words = options.showfavs.split()
  1378. if len(words) is 2:
  1379. user = words[0]
  1380. count = words[1]
  1381. else:
  1382. word = options.showfavs
  1383. try:
  1384. count = int(word)
  1385. except:
  1386. user = word
  1387. try:
  1388. status = api.GetFavorites(user_id=user,count=count)
  1389. return status, count
  1390. except URLError as u:
  1391. print "\n[Error] - ",u.reason.strerror, "\n"
  1392. if options.gtk:
  1393. return
  1394. else:
  1395. sys.exit(2)
  1396. except TwitterError as t:
  1397. print "\n[Error] - ",t, "\n"
  1398. if options.gtk:
  1399. return
  1400. else:
  1401. sys.exit(2)
  1402. def save_favorites(self):
  1403. """
  1404. Save Favorites
  1405. """
  1406. options = self.options
  1407. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1408. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1409. count = 10
  1410. user = ""
  1411. words = options.savefavs.split()
  1412. if len(words) is 2:
  1413. user = words[0]
  1414. count = words[1]
  1415. else:
  1416. word = options.savefavs
  1417. try:
  1418. count = int(word)
  1419. except:
  1420. user = word
  1421. try:
  1422. status = api.GetFavorites(user_id=user,count=count)
  1423. return status, user
  1424. except URLError as u:
  1425. print "\n[Error] - ",u.reason.strerror, "\n"
  1426. if options.gtk:
  1427. return
  1428. else:
  1429. sys.exit(2)
  1430. except TwitterError as t:
  1431. print "\n[Error] - ",t, "\n"
  1432. if options.gtk:
  1433. return
  1434. else:
  1435. sys.exit(2)
  1436. def short_url(self):
  1437. """
  1438. Short URL
  1439. """
  1440. options = self.options
  1441. proxy = options.proxy
  1442. eprint = sys.stderr.write
  1443. proxy_info = None
  1444. if proxy is not None:
  1445. try:
  1446. match = re.finditer(":",proxy)
  1447. positionlist = []
  1448. for m in match:
  1449. positionlist.append(m.start())
  1450. pos1 = positionlist[0]
  1451. pos2 = positionlist[1]
  1452. host = proxy[pos1+3:pos2]
  1453. slen = len(proxy)
  1454. port = proxy[pos2+1:slen]
  1455. proxy_info = core.socks.setdefaultproxy(core.socks.PROXY_TYPE_HTTP, host, int(port))
  1456. socket.socket = core.socks.socksocket
  1457. except IndexError:
  1458. eprint ("\n[Error] - Proxy is malformed. For example, to launch with TOR use: --proxy 'http://127.0.0.1:8118'")
  1459. eprint ("\nAborting...\n")
  1460. if options.gtk:
  1461. return
  1462. else:
  1463. sys.exit(2)
  1464. except ValueError:
  1465. eprint ("[Error] - Proxy is malformed. For example, to launch with TOR use: --proxy 'http://127.0.0.1:8118'")
  1466. eprint ("\nAborting...\n")
  1467. if options.gtk:
  1468. return
  1469. else:
  1470. sys.exit(2)
  1471. shortener = ShortURLReservations()
  1472. shortener = shortener.process_url(options.shorturl, proxy)
  1473. print "\nShort url:", shortener, "\n"
  1474. return shortener
  1475. def IRCdeploy(self, user, host, port, chan):
  1476. """
  1477. Deploy IRC Bot
  1478. """
  1479. from core.irc.bot import AnonTwiIrcBot
  1480. AnonBot = AnonTwiIrcBot().run (user, host, port, chan)
  1481. return AnonBot
  1482. def get_status(self,id):
  1483. """
  1484. Get Status
  1485. """
  1486. options = self.options
  1487. tokens = self.try_running(self.get_env_tokens, "\nInternal error getting -Tokens- ")
  1488. api = core.twitter.Api(self.consumer_key, self.consumer_secret, self.access_token_key, self.access_token_secret, proxy=options.proxy, request_headers=self.request_headers)
  1489. try:
  1490. status = api.GetStatus(id=id)
  1491. return status
  1492. except URLError as u:
  1493. print "\n[Error] - ",u.reason.strerror, "\n"
  1494. if options.gtk:
  1495. return
  1496. else:
  1497. sys.exit(2)
  1498. except TwitterError as t:
  1499. print "\n[Error] - ",t, "\n"
  1500. if options.gtk:
  1501. return
  1502. else:
  1503. sys.exit(2)
  1504. def run(self, opts=None):
  1505. """
  1506. Run AnonTwi
  1507. """
  1508. eprint = sys.stderr.write
  1509. if opts:
  1510. options = self.create_options(opts)
  1511. self.set_options(options)
  1512. options = self.options
  1513. p = self.optionParser
  1514. # check proxy options
  1515. proxy = options.proxy
  1516. if options.proxy:
  1517. try:
  1518. pattern = 'http[s]?://(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]):[0-9][0-9][0-9]?[0-9]?[0-9]?'
  1519. m = re.search(pattern, proxy)
  1520. if m is None:
  1521. print('='*75)
  1522. print(str(self.optionParser.version))
  1523. print('='*75)
  1524. print ("\n[Error] - Proxy is malformed. For example, to launch with TOR use: --proxy 'http://127.0.0.1:8118'")
  1525. print ("\nAborting...\n")
  1526. if options.gtk:
  1527. return
  1528. else:
  1529. sys.exit(2)
  1530. except Exception:
  1531. print('='*75)
  1532. print(str(self.optionParser.version))
  1533. print('='*75)
  1534. print ("\n[Error] - Proxy is malformed. For example, to launch with TOR use: --proxy 'http://127.0.0.1:8118'")
  1535. print ("\nAborting...\n")
  1536. if options.gtk:
  1537. return
  1538. else:
  1539. sys.exit(2)
  1540. # if options.webserver:
  1541. # eprint("Running webserver\n")
  1542. # AnonTwiWebserver(self)
  1543. # sys.exit(0)
  1544. if options.ircbot:
  1545. eprint("Running irc bot client\n")
  1546. if options.gtk:
  1547. pass
  1548. else:
  1549. try:
  1550. [user, rest] = options.ircbot.split ('@')
  1551. except Exception, e:
  1552. import random
  1553. import string
  1554. char_set = string.ascii_uppercase + string.ascii_lowercase + string.digits
  1555. char_prefix = string.ascii_lowercase + string.ascii_uppercase
  1556. user_pre = ''.join(random.sample(char_prefix,2))
  1557. user = ''.join(random.sample(char_set,10))
  1558. user = user_pre + user
  1559. #user = "anontwibot"
  1560. rest = options.ircbot
  1561. try:
  1562. [host, port] = rest.split (':')
  1563. except Exception:
  1564. print "\nPlease specify irc host and port, correctly!\n"
  1565. sys.exit(1)
  1566. try:
  1567. [port, chan] = port.split ('#')
  1568. except Exception:
  1569. chan = ""
  1570. print "\nNo channel specified. Assigning a random one to deploy bot\n"
  1571. char_set = string.ascii_uppercase + string.ascii_lowercase + string.digits
  1572. char_prefix = string.ascii_lowercase + string.ascii_uppercase
  1573. chan_pre = ''.join(random.sample(char_prefix,2))
  1574. chan = ''.join(random.sample(char_set,10))
  1575. chan = chan_pre + chan
  1576. self.IRCdeploy(user, host, port, chan)
  1577. sys.exit(0)
  1578. if options.gtk:
  1579. from core.gtk.anontwigtk import AnontwiGTK
  1580. AnontwiGTK.run()
  1581. sys.exit(0)
  1582. # step 0: tokens, list searches, timelines, friendships, favorites
  1583. if options.tokens:
  1584. eprint('='*75+'\n')
  1585. eprint(str(p.version)+'\n')
  1586. eprint('='*75+'\n')
  1587. if options.rgb:
  1588. eprint("Getting your API tokens (\033[1;31mkey\033[1;m & \033[1;31msecret\033[1;m)...\n")
  1589. else:
  1590. eprint("Getting your API tokens (key & secret)...\n")
  1591. eprint('='*75+"\n")
  1592. #self.try_running(self.request_tokens, "\nInternal error getting access tokens ", ())
  1593. tokens = self.request_url()
  1594. self.insert_pincode(tokens[0],
  1595. tokens[1],
  1596. self.consumer_key,
  1597. self.consumer_secret)
  1598. if options.search:
  1599. print('='*75)
  1600. print(str(p.version))
  1601. print('='*75)
  1602. self.search = options.search
  1603. words = options.search.split()
  1604. if len(words) is 2:
  1605. self.search = words[0]
  1606. if options.rgb:
  1607. print("Starting to search:"), "\033[1;34m", self.search, "\033[1;m"
  1608. else:
  1609. print("Starting to search:"), options.search
  1610. print('='*75), "\n"
  1611. searches = self.try_running(self.search_messages, "\nInternal error searching -message-. look at the end of this Traceback.")
  1612. if len(searches) <= 0:
  1613. print "Search doesn't get any results.\n"
  1614. if options.gtk:
  1615. return
  1616. else:
  1617. sys.exit(2)
  1618. else:
  1619. print("Search Results:")
  1620. h = HTMLParser.HTMLParser()
  1621. for s in searches:
  1622. print "======"
  1623. if options.rgb:
  1624. if s.user.name is not None:
  1625. print "Name:\033[1;31m", h.unescape(s.user.name), "\033[1;m", "- Nick:\033[1;34m", s.user.screen_name, "\033[1;m"
  1626. else:
  1627. print "Nick:\033[1;34m", s.user.screen_name, "\033[1;m"
  1628. else:
  1629. if s.user.name is not None:
  1630. print "Name:", h.unescape(s.user.name), "- Nick:", s.user.screen_name
  1631. else:
  1632. print "Nick:", s.user.screen_name
  1633. if options.rgb:
  1634. print "Tweet-ID:\033[1;36m", s.id, "\033[1;m"
  1635. else:
  1636. print "Tweet-ID:", s.id
  1637. if options.rgb:
  1638. print s.created_at
  1639. else:
  1640. print s.created_at
  1641. if options.rgb:
  1642. print "\033[1;37m", h.unescape(s.text), "\033[1;m"
  1643. else:
  1644. print h.unescape(s.text)
  1645. if s.place is not None:
  1646. if options.rgb:
  1647. print "Location: \033[1;31m", s.place["name"], "\033[1;m"
  1648. else:
  1649. print "Location:", s.place["name"]
  1650. print "======", "\n"
  1651. if options.topics:
  1652. print('='*75)
  1653. print(str(p.version))
  1654. print('='*75)
  1655. print("Seaching Global Trending Topics (TT) ")
  1656. print('='*75), "\n"
  1657. if self.source_api == "api.twitter.com":
  1658. trendingtopics = self.try_running(self.search_topics, "\nInternal error searching -trending topics-. look at the end of this Traceback.")
  1659. else:
  1660. print "[Info] This feature is not allowed by GNUSocial yet...\n"
  1661. trendingtopics = 0
  1662. if trendingtopics is None or len(trendingtopics) <= 0:
  1663. print "Something wrong getting trending topics... Aborting!\n"
  1664. if options.gtk:
  1665. return
  1666. else:
  1667. sys.exit(2)
  1668. else:
  1669. print("Trending Topics:")
  1670. h = HTMLParser.HTMLParser()
  1671. print("========\n")
  1672. for t in trendingtopics:
  1673. self.topic = t.name
  1674. if options.rgb:
  1675. print "\033[1;31m", h.unescape(self.topic), "\033[1;m"
  1676. else:
  1677. print(h.unescape(self.topic))
  1678. print "======", "\n"
  1679. if options.suicide:
  1680. print('='*75)
  1681. print(str(p.version))
  1682. print('='*75)
  1683. print("Suiciding !!!!!!! :-D ")
  1684. print('='*75), "\n"
  1685. # ask question to be sure
  1686. print "You go to 'remove' your account, for that, AnonTwi will try to delete all your tweets"
  1687. print "and direct messages. Remember that some social networks were storing your data on their servers"
  1688. print "so, this process will use the tools that the API that you are connecting using AnonTwi allows to you to use\n"
  1689. print "If you had a lot of activity, it can takes long time. After remove ALL data, your account will be deactivated...\n"
  1690. zen = raw_input("Ready (y/n)")
  1691. if zen is "y":
  1692. print "\nStarting to destroy your data:"
  1693. print "------------------------------\n"
  1694. # remove all tweets
  1695. suicides = self.try_running(self.suicide, "\nInternal error -suiciding-. look at the end of this Traceback.")
  1696. print "All data correctly deleted!\n"
  1697. # close account
  1698. if self.source_api == "api.twitter.com":
  1699. print "[Info] Remember that Twitter.com does not delete your data. If you want to deactive your account, you must to"
  1700. print " do some some steps. Follow this link to complete your suicide:\n"
  1701. print " https://support.twitter.com/articles/15358-how-to-deactivate-your-account#\n"
  1702. print "[Info] You should reclaim your rights about your personal data. Twitter.com is in California.\n"
  1703. else:
  1704. print "\nWhen you cease to make a contribution, then you begin to die. Anna Eleanor Roosevelt.\n"
  1705. if options.mentions:
  1706. print('='*75)
  1707. print(str(p.version))
  1708. print('='*75)
  1709. print("Showing mentions about you...")
  1710. print('='*75), "\n"
  1711. (mentions, num) = self.try_running(self.show_mentions, "\nInternal error searching -mentions- about you. look at the end of this Traceback.")
  1712. if len(mentions) <= 0:
  1713. print "Search doesn't get any results.\n"
  1714. if options.gtk:
  1715. return
  1716. else:
  1717. sys.exit(2)
  1718. else:
  1719. print("Mentions:")
  1720. print("========")
  1721. n = int(len(mentions))
  1722. h = HTMLParser.HTMLParser()
  1723. if int(num) < int(len(mentions)):
  1724. n = int(num)
  1725. for i in range(int(n)):
  1726. if options.rgb:
  1727. print "Name:\033[1;31m", h.unescape(mentions[i].user.name), "\033[1;m", "- Nick:\033[1;34m", mentions[i].user.screen_name, "\033[1;m"
  1728. else:
  1729. print "Name:", h.unescape(mentions[i].user.name), "- Nick:", mentions[i].user.screen_name
  1730. if options.rgb:
  1731. print "Tweet-ID:\033[1;36m", mentions[i].id, "\033[1;m"
  1732. else:
  1733. print "Tweet-ID:", mentions[i].id
  1734. if options.rgb:
  1735. print mentions[i].created_at
  1736. else:
  1737. print mentions[i].created_at
  1738. if options.rgb:
  1739. print "\033[1;37m", h.unescape(mentions[i].text), "\033[1;m"
  1740. else:
  1741. print h.unescape(mentions[i].text)
  1742. if mentions[i].place is not None:
  1743. if options.rgb:
  1744. print "\033[1;37m", mentions[i].place["name"], "\033[1;m"
  1745. else:
  1746. print mentions[i].place["name"]
  1747. else:
  1748. pass
  1749. print "======"
  1750. if options.timeline:
  1751. print('='*75)
  1752. print(str(p.version))
  1753. print('='*75)
  1754. self.timeline = options.timeline
  1755. words = options.timeline.split()
  1756. if len(words) is 2:
  1757. self.timeline = words[0]
  1758. if options.rgb:
  1759. print("Showing timeline of:"), "\033[1;34m", self.timeline, "\033[1;m"
  1760. else:
  1761. print("Showing timeline of:"), options.timeline
  1762. h = HTMLParser.HTMLParser()
  1763. print('='*75), "\n"
  1764. timelines = self.try_running(self.show_timeline, "\nInternal error searching -timeline-. look at the end of this Traceback.")
  1765. if len(timelines) <= 0:
  1766. print "This user hasn't tweeted yet.\n"
  1767. if options.gtk:
  1768. return
  1769. else:
  1770. sys.exit(2)
  1771. else:
  1772. print("Name:"),
  1773. for s in timelines:
  1774. self.nickid = h.unescape(s.user.name)
  1775. if options.rgb:
  1776. print "\033[1;31m", self.nickid, "\033[1;m"
  1777. else:
  1778. print(self.nickid)
  1779. print("Nick:"),
  1780. for s in timelines:
  1781. user = s.user.screen_name
  1782. if options.rgb:
  1783. print "\033[1;34m", s.user.screen_name, "\033[1;m"
  1784. else:
  1785. print(user)
  1786. print("Description:"),
  1787. for s in timelines:
  1788. if s.user.description:
  1789. description = h.unescape(s.user.description)
  1790. else:
  1791. description = ""
  1792. if options.rgb:
  1793. print"\033[1;30m", description, "\033[1;m"
  1794. else:
  1795. print(description)
  1796. print("Friends:"),
  1797. for s in timelines:
  1798. friends = s.user.friends_count
  1799. if options.rgb:
  1800. print "\033[1;32m", friends, "\033[1;m"
  1801. else:
  1802. print(friends)
  1803. print("Followers:"),
  1804. for s in timelines:
  1805. followers = s.user.followers_count
  1806. if options.rgb:
  1807. print "\033[1;32m", followers, "\033[1;m"
  1808. else:
  1809. print(followers)
  1810. print "Timeline requests:"
  1811. print("---------")
  1812. for s in timelines:
  1813. if options.rgb:
  1814. print "Tweet-ID:", "\033[1;36m", s.id, "\033[1;m"
  1815. else:
  1816. print "Tweet-ID:", s.id
  1817. if options.rgb:
  1818. print s.created_at
  1819. else:
  1820. print s.created_at
  1821. if options.rgb:
  1822. print "\033[1;37m", h.unescape(s.text), "\033[1;m"
  1823. else:
  1824. print h.unescape(s.text)
  1825. if s.place is not None:
  1826. if options.rgb:
  1827. print "Location: \033[1;35m", s.place["name"], "\033[1;m"
  1828. else:
  1829. print "Location:", s.place["name"]
  1830. print "======"
  1831. if options.timelinedm:
  1832. print('='*75)
  1833. print(str(p.version))
  1834. print('='*75)
  1835. print("Showing Direct Messages...")
  1836. h = HTMLParser.HTMLParser()
  1837. print('='*75), "\n"
  1838. (dms, num) = self.try_running(self.show_timelinedm, "\nInternal error searching -direct messages-. look at the end of this Traceback.")
  1839. if len(dms) <= 0:
  1840. print "Search doesn't get any results.\n"
  1841. if options.gtk:
  1842. return
  1843. else:
  1844. sys.exit(2)
  1845. else:
  1846. print "Your conversations:"
  1847. print("---------")
  1848. n = int(len(dms))
  1849. if int(num) < int(len(dms)):
  1850. n = int(num)
  1851. for i in range(int(n)):
  1852. if options.rgb:
  1853. print "DM-ID:\033[1;31m", dms[i].id, "\033[1;m"
  1854. else:
  1855. print "DM-ID:", dms[i].id
  1856. if options.rgb:
  1857. print dms[i].created_at
  1858. else:
  1859. print dms[i].created_at
  1860. if options.rgb:
  1861. print "From:\033[1;34m", h.unescape(dms[i].sender_screen_name), "\033[1;m"
  1862. else:
  1863. print "From:", h.unescape(dms[i].sender_screen_name)
  1864. if options.rgb:
  1865. print "\033[1;37m", h.unescape(dms[i].text), "\033[1;m"
  1866. else:
  1867. print h.unescape(dms[i].text)
  1868. print "======"
  1869. if options.timelinef:
  1870. print('='*75)
  1871. print(str(p.version))
  1872. print('='*75)
  1873. print("Showing your 'home' timeline")
  1874. h = HTMLParser.HTMLParser()
  1875. print('='*75), "\n"
  1876. num = options.timelinef
  1877. (timelinesf, count) = self.try_running(self.show_timeline_friends, "\nInternal error searching -timeline-. look at the end of this Traceback.")
  1878. if len(timelinesf) <= 0:
  1879. print "This user hasn't tweeted yet.\n"
  1880. if options.gtk:
  1881. return
  1882. else:
  1883. sys.exit(2)
  1884. else:
  1885. print "Timeline requests:"
  1886. print "---------"
  1887. if int(len(timelinesf)) < int(count):
  1888. count = int(len(timelinesf))
  1889. for i in range(int(count)):
  1890. if options.rgb:
  1891. print "Name:\033[1;31m", h.unescape(timelinesf[i].user.name), "\033[1;m", "- Nick:\033[1;34m", timelinesf[i].user.screen_name, "\033[1;m"
  1892. #print("Description:"), "\033[1;30m", timelinesf[i].user.description, "\033[1;m"
  1893. #print("Friends:"), "\033[1;32m", timelinesf[i].user.friends_count, "\033[1;m"
  1894. #print("Followers:"), "\033[1;32m", timelinesf[i].user.followers_count, "\033[1;m"
  1895. else:
  1896. print "Name:", h.unescape(timelinesf[i].user.name), "- Nick:", timelinesf[i].user.screen_name
  1897. #print("Description:"), timelinesf[i].user.description
  1898. #print("Friends:"), timelinesf[i].user.friends_count
  1899. #print("Followers:"), timelinesf[i].user.followers_count
  1900. #print "\nTimeline requests:"
  1901. if options.rgb:
  1902. print "Tweet-ID:", "\033[1;36m", timelinesf[i].id, "\033[1;m"
  1903. else:
  1904. print "Tweet-ID:", timelinesf[i].id
  1905. if options.rgb:
  1906. print timelinesf[i].created_at
  1907. else:
  1908. print timelinesf[i].created_at
  1909. if options.rgb:
  1910. print "\033[1;37m", h.unescape(timelinesf[i].text), "\033[1;m"
  1911. else:
  1912. print h.unescape(timelinesf[i].text)
  1913. if timelinesf[i].place is not None:
  1914. if options.rgb:
  1915. print "Location: \033[1;35m", timelinesf[i].place["name"], "\033[1;m"
  1916. else:
  1917. print "Location:", timelinesf[i].place["name"]
  1918. print "======"
  1919. if options.showfavs:
  1920. print('='*75)
  1921. print(str(p.version))
  1922. print('='*75)
  1923. print("Showing favorites")
  1924. h = HTMLParser.HTMLParser()
  1925. print('='*75), "\n"
  1926. (favorites, count) = self.try_running(self.show_favorites, "\nInternal error searching -favorites-. look at the end of this Traceback.")
  1927. if len(favorites) <= 0:
  1928. print "No results.\n"
  1929. if options.gtk:
  1930. return
  1931. else:
  1932. sys.exit(2)
  1933. else:
  1934. if int(len(favorites)) < int(count):
  1935. count = int(len(favorites))
  1936. for i in range(int(count)):
  1937. if options.rgb:
  1938. print "Name:\033[1;31m", h.unescape(favorites[i].user.name), "\033[1;m", "- Nick:\033[1;34m", favorites[i].user.screen_name, "\033[1;m"
  1939. else:
  1940. print "Name:", h.unescape(favorites[i].user.name), "- Nick:", favorites[i].user.screen_name
  1941. if options.rgb:
  1942. print "Tweet-ID:", "\033[1;36m", favorites[i].id, "\033[1;m"
  1943. else:
  1944. print "Tweet-ID:", favorites[i].id
  1945. if options.rgb:
  1946. print favorites[i].created_at
  1947. else:
  1948. print favorites[i].created_at
  1949. if options.rgb:
  1950. print "\033[1;37m", h.unescape(favorites[i].text), "\033[1;m"
  1951. else:
  1952. print h.unescape(favorites[i].text)
  1953. if favorites[i].place is not None:
  1954. if options.rgb:
  1955. print "Location: \033[1;35m", favorites[i].place["name"], "\033[1;m"
  1956. else:
  1957. print "Location:", favorites[i].place["name"]
  1958. print "=================="
  1959. # step 1: get message/image/DM to send and sanitize them
  1960. messages = self.try_running(self.get_messages, "\nInternal error getting -message-. look at the end of this Traceback.")
  1961. #(messages, dm, image) = self.sanitize_messages(messages)
  1962. (messages, dm) = self.sanitize_messages(messages)
  1963. # send retweets
  1964. retweets = self.try_running(self.get_tweetids, "\nInternal error sending -retweet-. look at the end of this Traceback.")
  1965. # remove tweets
  1966. tweet_removed = False
  1967. if options.rmtweet:
  1968. rmtweets = self.try_running(self.remove_tweet, "\nInternal error removing -message-. look at the end of this Traceback.")
  1969. tweet_removed = True
  1970. # remove direct messages
  1971. if options.rmdm:
  1972. rmdms = self.try_running(self.remove_dm, "\nInternal error removing -direct message-. look at the end of this Traceback.")
  1973. # step 2: de/encryption processes
  1974. if options.encaes:
  1975. key = options.key
  1976. try:
  1977. messages = self.encrypt(messages, key)
  1978. except ValueError:
  1979. print len(key)
  1980. print "\n[Error] - Invalid PIN key. Try to generate automatically (ex: --gen)"
  1981. print "\nAborting...\n"
  1982. if options.gtk:
  1983. return
  1984. else:
  1985. sys.exit(2)
  1986. if options.decaes:
  1987. key = options.key
  1988. try:
  1989. self.decrypt(messages, key)
  1990. except ValueError:
  1991. print "\n[Error] - Invalid PIN key. Try to generate automatically (ex: --gen)"
  1992. print "\nAborting...\n"
  1993. if options.gtk:
  1994. return
  1995. else:
  1996. sys.exit(2)
  1997. # step3: send tweet/waves/DM
  1998. if options.tweet and not options.decaes:
  1999. if options.dm:
  2000. dm = self.try_running(self.send_dm, "\nInternal error sending -DM- ", (messages, dm))
  2001. print "[Info] DM sent correctly!", "\n"
  2002. elif options.wave:
  2003. if options.location:
  2004. (latitude, longitude) = self.get_location()
  2005. if options.reply:
  2006. reply = options.reply
  2007. else:
  2008. reply = None
  2009. waves = self.try_running(self.send_wave, "\nInternal error sending -Wave- ", (messages, reply, latitude, longitude))
  2010. print "[Info] Your geolocation place was changed to coordenates:", latitude, ",", longitude
  2011. if options.reply:
  2012. print "\n[Info] Waves reply to conversation sent correctly!", "\n"
  2013. else:
  2014. print "\n[Info] Waves sent correctly!", "\n"
  2015. else:
  2016. if options.reply:
  2017. reply = options.reply
  2018. else:
  2019. reply = None
  2020. waves = self.try_running(self.send_wave, "\nInternal error sending -Wave- ", (messages, reply, None, None))
  2021. if options.reply:
  2022. print "\n[Info] Waves reply to conversation sent correctly!", "\n"
  2023. else:
  2024. print "\n[Info] Waves sent correctly!", "\n"
  2025. # fake geolocation
  2026. elif options.location and not options.wave:
  2027. (latitude, longitude) = self.get_location()
  2028. # reply to tweet conversation with fake geolocation
  2029. if options.reply:
  2030. reply = options.reply
  2031. else:
  2032. reply = None
  2033. tweet = self.try_running(self.send_tweet, "\nInternal error sending -Tweet- ", (messages, reply, latitude, longitude))
  2034. print "[Info] Your geolocation place was changed to coordenates:", latitude, ",", longitude
  2035. if options.reply:
  2036. print "\n[Info] Tweet reply to conversation sent correctly!", "\n"
  2037. else:
  2038. print "\n[Info] Tweet sent correctly!", "\n"
  2039. else:
  2040. # reply to tweet conversation
  2041. if options.reply:
  2042. reply = options.reply
  2043. else:
  2044. reply = None
  2045. tweet = self.try_running(self.send_tweet, "\nInternal error sending -Tweet- ", (messages, reply, None, None))
  2046. if options.reply:
  2047. print "\n[Info] Tweet reply to conversation sent correctly!", "\n"
  2048. else:
  2049. print "\n[Info] Tweet sent correctly!", "\n"
  2050. # send image
  2051. #elif options.image:
  2052. # images = self.try_running(self.send_image, "\nInternal error sending -Image- " (messages, image))
  2053. # print "[Info] Image uploaded correctly!", "\n"
  2054. # send retweet
  2055. elif options.retweet:
  2056. retweet = self.try_running(self.send_retweet, "\nInternal error sending -reTweet- ", retweets)
  2057. print "\n[Info] reTweet sent correctly!", "\n"
  2058. # remove tweet
  2059. elif options.rmtweet:
  2060. if not tweet_removed:
  2061. rmtweet = self.try_running(self.remove_tweet, "\nInternal error removing -message- ", rmtweets)
  2062. print "\n[Info] Tweet removed correctly!", "\n"
  2063. # remove direct message
  2064. elif options.rmdm:
  2065. rmdm = self.try_running(self.remove_dm, "\nInternal error removing -message- ", rmdms)
  2066. print "\n[Info] Direct Message removed correctly!", "\n"
  2067. # create friendship
  2068. if options.friend:
  2069. friend = self.try_running(self.set_friend, "\nInternal error creating -friendship- ")
  2070. print "\n[Info] Your request to friendship with:", options.friend, "was successfully sent!", "\n"
  2071. # create massive friendship from file (file.txt)
  2072. #if options.massfriend:
  2073. # friend = self.try_running(self.set_friend, "\nInternal error creating -friendship- ")
  2074. # print "[Info] Your request to friendship list was successfully sent!", "\n"
  2075. # destroy friendship
  2076. if options.dfriend:
  2077. dfriend = self.try_running(self.remove_friend, "\nInternal error destroying -friendship- ")
  2078. print "\n[Info] Your request to destroy friendship with:", options.dfriend, "was successfully sent!", "\n"
  2079. # create block
  2080. if options.block:
  2081. block = self.try_running(self.create_block, "\nInternal error destroying -friendship- ")
  2082. print "\n[Info] Your request to create block with:", options.block, "was successfully sent!", "\n"
  2083. # destroy block
  2084. if options.unblock:
  2085. unblock = self.try_running(self.destroy_block, "\nInternal error destroying -friendship- ")
  2086. print "\n[Info] Your request to destroy block with:", options.unblock, "was successfully sent!", "\n"
  2087. # create favorite
  2088. if options.favorite:
  2089. favorite = self.try_running(self.create_favorite, "\nInternal error creating -favorite- ")
  2090. print "\n[Info] Your request to create favorite was successfully sent!", "\n"
  2091. # destroy favorite
  2092. if options.unfavorite:
  2093. favorite = self.try_running(self.destroy_favorite, "\nInternal error destroying -favorite- ")
  2094. print "\n[Info] Your request to destroy favorite was successfully sent!", "\n"
  2095. # change 'source' value
  2096. #if options.via:
  2097. # source = self.try_running(self.set_via, "\nInternal error setting -via- detailed on website ")
  2098. # print "[Info] Your 'via' value was changed to:", options.via, "\n"
  2099. # store tweets to disk
  2100. if options.save:
  2101. print('='*75)
  2102. print(str(p.version))
  2103. print('='*75)
  2104. h = HTMLParser.HTMLParser()
  2105. (saved,user) = self.try_running(self.save_timeline, "\nInternal error getting -Tokens- ")
  2106. if saved is None:
  2107. print("Saving messages:")
  2108. else:
  2109. if options.rgb:
  2110. print("Saving messages:"), "\033[1;34m", user, "\033[1;m"
  2111. else:
  2112. print("Saving messages:"), user
  2113. print('='*75), "\n"
  2114. if saved == []:
  2115. print "This user hasn't tweet anything yet.\n"
  2116. if options.gtk:
  2117. return
  2118. else:
  2119. sys.exit(2)
  2120. for s in saved:
  2121. if options.rgb:
  2122. print "[Saved]:", s.created_at,
  2123. print "\033[1;37m", h.unescape(s.text), "\033[1;m"
  2124. else:
  2125. print "[Saved]:", s.created_at, ":", h.unescape(s.text)
  2126. if not os.path.isdir("backups"):
  2127. os.mkdir("backups")
  2128. if not os.path.exists("backups/%s"%(user)):
  2129. path = os.mkdir("backups/%s"%(user))
  2130. path = "backups/%s"%(user)
  2131. # some unicode issues
  2132. logs = ''
  2133. logs = u' '.join((logs, s.text)).encode('utf-8').strip()
  2134. nick = ''
  2135. nick = u' '.join((nick, s.user.screen_name)).encode('utf-8').strip()
  2136. name = ''
  2137. name = u' '.join((name, s.user.name)).encode('utf-8').strip()
  2138. created_at = ''
  2139. created_at = u' '.join((created_at, s.created_at)).encode('utf-8').strip()
  2140. id = ''
  2141. id = u' '.join((id, str(s.id))).encode('utf-8').strip()
  2142. place = ''
  2143. if s.place is not None:
  2144. place = u' '.join((place, s.place["name"])).encode('utf-8').strip()
  2145. h = "/tweets.txt"
  2146. f = open(path+h, 'a')
  2147. f.write("Name: " + name + " - ")
  2148. f.write("Nick: " + nick + "\n")
  2149. f.write("Tweet-ID: " + id + "\n")
  2150. f.write(created_at + "\n")
  2151. f.write(logs + "\n")
  2152. if s.place is not None:
  2153. f.write(place + "\n")
  2154. f.write("======" + "\n")
  2155. f.close()
  2156. print "\n[Info] Congratulations. Your messages backup is done!", "\n"
  2157. # store favorites to disk
  2158. if options.savefavs:
  2159. print('='*75)
  2160. print(str(p.version))
  2161. print('='*75)
  2162. h = HTMLParser.HTMLParser()
  2163. (savedfavs,user) = self.try_running(self.save_favorites, "\nInternal error getting -Tokens- ")
  2164. if savedfavs is None:
  2165. print("Saving favorites:")
  2166. else:
  2167. if options.rgb:
  2168. print("Saving favorites:"), "\033[1;34m", user, "\033[1;m"
  2169. else:
  2170. print("Saving favorites:"), user
  2171. print('='*75), "\n"
  2172. if savedfavs == []:
  2173. print "This user hasn't create favorites yet.\n"
  2174. if options.gtk:
  2175. return
  2176. else:
  2177. sys.exit(2)
  2178. for s in savedfavs:
  2179. if options.rgb:
  2180. print "[Saved]:", s.created_at,
  2181. print "\033[1;37m", h.unescape(s.text), "\033[1;m"
  2182. else:
  2183. print "[Saved]:", s.created_at, ":", h.unescape(s.text)
  2184. if not os.path.isdir("backups"):
  2185. os.mkdir("backups")
  2186. if not os.path.exists("backups/%s"%(user)):
  2187. path = os.mkdir("backups/%s"%(user))
  2188. path = "backups/%s"%(user)
  2189. # some unicode issues
  2190. logs = ''
  2191. logs = u' '.join((logs, s.text)).encode('utf-8').strip()
  2192. nick = ''
  2193. nick = u' '.join((nick, s.user.screen_name)).encode('utf-8').strip()
  2194. name = ''
  2195. name = u' '.join((name, s.user.name)).encode('utf-8').strip()
  2196. created_at = ''
  2197. created_at = u' '.join((created_at, s.created_at)).encode('utf-8').strip()
  2198. id = ''
  2199. id = u' '.join((id, str(s.id))).encode('utf-8').strip()
  2200. place = ''
  2201. if s.place is not None:
  2202. place = u' '.join((place, s.place["name"])).encode('utf-8').strip()
  2203. h = "/favorites.txt"
  2204. f = open(path+h, 'a')
  2205. f.write("Name: " + name + " - ")
  2206. f.write("Nick: " + nick + "\n")
  2207. f.write("Tweet-ID: " + id + "\n")
  2208. f.write(created_at + "\n")
  2209. f.write(logs + "\n")
  2210. if s.place is not None:
  2211. f.write(place + "\n")
  2212. f.write("======" + "\n")
  2213. f.close()
  2214. print "\n[Info] Congratulations. Your favorites backup is done!", "\n"
  2215. # generate a PIN key if requested
  2216. if options.genkey:
  2217. key = generate_key()
  2218. print "\nPIN key:", key, "\n\nShare this key privately with the recipients of your encrypted messages.\nDon't send this key over insecure channels such as email, SMS, IM or Twitter.\nUse the sneakernet! ;)\n"
  2219. # generate a short url if requested
  2220. if options.shorturl:
  2221. proxy = options.proxy
  2222. eprint = sys.stderr.write
  2223. proxy_info = None
  2224. if proxy is not None:
  2225. try:
  2226. match = re.finditer(":",proxy)
  2227. positionlist = []
  2228. for m in match:
  2229. positionlist.append(m.start())
  2230. pos1 = positionlist[0]
  2231. pos2 = positionlist[1]
  2232. host = proxy[pos1+3:pos2]
  2233. slen = len(proxy)
  2234. port = proxy[pos2+1:slen]
  2235. proxy_info = core.socks.setdefaultproxy(core.socks.PROXY_TYPE_HTTP, host, int(port))
  2236. socket.socket = core.socks.socksocket
  2237. except IndexError:
  2238. eprint ("\n[Error] - Proxy is malformed. For example, to launch with TOR use: --proxy 'http://127.0.0.1:8118'")
  2239. eprint ("\nAborting...\n")
  2240. if options.gtk:
  2241. return
  2242. else:
  2243. sys.exit(2)
  2244. except ValueError:
  2245. eprint ("[Error] - Proxy is malformed. For example, to launch with TOR use: --proxy 'http://127.0.0.1:8118'")
  2246. eprint ("\nAborting...\n")
  2247. if options.gtk:
  2248. return
  2249. else:
  2250. sys.exit(2)
  2251. shortener = ShortURLReservations()
  2252. shortener = shortener.process_url(options.shorturl, proxy)
  2253. print "\nShort url:", shortener, "\n"
  2254. def sanitize_messages(self, messages):
  2255. """
  2256. Sanitize correct input of message/image/dm to send
  2257. """
  2258. options = self.options
  2259. all_messages = set()
  2260. dm_user = set()
  2261. #image = set()
  2262. for message in messages:
  2263. if options.tweet:
  2264. lenght_tweet = len(options.tweet)
  2265. self.num_tweets = int(lenght_tweet/140) + 1 #140 characters/tweet
  2266. if options.rgb:
  2267. print "\nMessage [ \033[1;34mNumber of words:\033[1;m\033[1;37m", lenght_tweet, "\033[1;m- \033[1;34mNumber of waves:\033[1;m\033[1;37m", self.num_tweets, "\033[1;m]"
  2268. else:
  2269. print "\nMessage [ Number of words:", lenght_tweet, "- Number of waves:", self.num_tweets, "]"
  2270. print "-------------"
  2271. if options.rgb:
  2272. print "\033[1;35m", options.tweet, "\033[1;m"
  2273. else:
  2274. print options.tweet
  2275. print "-------------"
  2276. all_messages.add(options.tweet)
  2277. if options.dm:
  2278. if "@" in options.dm and not "api.twitter.com" in self.source_api:
  2279. user=options.dm.strip()[1:len(options.dm.strip())]
  2280. options.dm = user
  2281. if options.rgb:
  2282. print "To:\033[1;31m", options.dm, "\033[1;m"
  2283. else:
  2284. print "To:", options.dm
  2285. print "------\n"
  2286. dm_user.add(options.dm)
  2287. if options.dm and not options.tweet:
  2288. print "\n[Error] - you must enter a message to send, using option -m (ex: -d '@nick' -m 'text')\n"
  2289. if options.gtk:
  2290. return
  2291. else:
  2292. sys.exit(2)
  2293. #return all_messages, dm_user, image
  2294. return all_messages, dm_user
  2295. #GTK/Wrapper
  2296. def get_user_info(self,
  2297. consumer_key,
  2298. consumer_secret,
  2299. access_token_key,
  2300. access_token_secret,
  2301. proxy):
  2302. """
  2303. Get user info
  2304. """
  2305. api = core.twitter.Api(consumer_key, consumer_secret, access_token_key, access_token_secret, proxy=proxy, request_headers=self.request_headers)
  2306. try:
  2307. if self.source_api == "api.twitter.com":
  2308. status = api.GetUserTimeline(api.VerifyCredentials().screen_name, count=0, include_rts=1)
  2309. else:
  2310. status = api.GetUserTimeline(screen_name=api.VerifyCredentials().screen_name, count=0, include_rts=1)
  2311. except TwitterError as t:
  2312. print "[Error] - ",t,"\n"
  2313. for s in status:
  2314. nickid = s.user.name
  2315. user = s.user.screen_name
  2316. description = s.user.description
  2317. friends = s.user.friends_count
  2318. followers = s.user.followers_count
  2319. #following = s.user.following_count
  2320. url_profile = s.user.profile_image_url
  2321. statuses_count = s.user.statuses_count
  2322. user_info = {'nickid':nickid,
  2323. 'user':user,
  2324. 'description':description,
  2325. 'friends':friends,
  2326. 'followers':followers,
  2327. 'url_profile':url_profile,
  2328. 'statuses_count':statuses_count}
  2329. #'following':following}
  2330. return user_info
  2331. if __name__ == "__main__":
  2332. app = anontwi()
  2333. options = app.create_options()
  2334. if options:
  2335. app.set_options(options)
  2336. app.run()