Kymru
Posts: 18
Joined: Tue Aug 06, 2013 11:28 am
Location: Y Drenewydd, Cymru

Twitter Reporter

Mon Nov 23, 2015 3:01 pm

i have a few RPi's laying around doing nothing, so i thought i would put one to use by turning it into a Privoxy + Tor server

on my quest to find info on how to do this again i come across a project from Anonymous about a twitter reporter, scanning over the one file i noticed you could use Privoxy and Tor

went though the motions of installing it, following this Linky thing, go to the end and got this little error:-

RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox

anyone know how to over come this problem?


using latest Raspbian by the way

Distributor ID: Debian
Description: Debian GNU/Linux 7.8 (wheezy)
Release: 7.8
Codename: wheezy

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Twitter Reporter

Mon Nov 23, 2015 4:11 pm

Are you trying to send or receive tweets?

Reading a timeline with python and tweepy is trivial.

Code: Select all

#!/usr/bin/python
import tweepy


Ckey = "redactedConsumerKey"
Csec = "redactedmyVerySecureConsumerSecret"
Akey = "redactedApplicationKey"
Asec = "redactedmyVerySecureApplicationSecret"

auth = tweepy.OAuthHandler(Ckey, Csec)
auth.set_access_token(Akey, Asec)
twapi = tweepy.API(auth)

mymentions= twapi.mentions_timeline(count=10)
for status in mymentions:
  print " "
  print status.text, "by @" + status.user.screen_name + " "
Sending a tweet is almost as simple.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Kymru
Posts: 18
Joined: Tue Aug 06, 2013 11:28 am
Location: Y Drenewydd, Cymru

Re: Twitter Reporter

Mon Nov 23, 2015 5:03 pm

DougieLawson wrote:Are you trying to send or receive tweets?
it would be send a tweet i guess, after following the link in my last post, saving the code below as TR5.py

when i run python TR5.py -u TWITTER -i 5K.txt i get the error RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox

but Debian doesnt come with Firefox, just Iceweasel

Code: Select all

#!/usr/bin/env python
#-*- coding: utf-8 -*-
#################################################################################
#NAME: TR5	// TWITTER AUTOREPORTER 5.0					#
#OP: #opIceISIS // #opFocalpoint						#
#										#
#USAGE:	$ cd YOUR_DOWNLOAD_FOLDER						#
# 	$ python TR5.py -u TWITTER_USERNAME -i TWITTER_URL_ONLY_TARGETSLIST.txt	#
#################################################################################

from splinter import Browser
import sys, getopt, re
from datetime import datetime
from splinter.request_handler.status_code import HttpResponseError
import time

def main(argv):
    
    d = datetime.now()
    date = str(d.year) + '' + str(d.month) + '' + str(d.day) + '' + str(d.hour) + '' + str(d.minute) + '' + str(d.second)
    try:
        opts, args = getopt.getopt(argv,"hi:u:",["file=","user="])
    except getopt.GetoptError:
        print 'twitterReport.py -u <Twitter username> -i <file>'
        print 'Le fichier des profiles doit comporter une URL par ligne ++'
#        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            print 'twitterReport.py -u <Twitter username> -i <file.txt>'
            print 'Le fichier des profiles doit comporter une URL par ligne'
            sys.exit()
        elif opt in ("-i", "--file"):
            txt = arg
        elif opt in ("-u", "--user"):
            username = arg

    password = raw_input("Enter your twitter password : ")

    try:
        username
        txt
    except getopt.GetoptError:
        print 'twitterReport.py -u <Twitter username> -i <file>'
        print 'Le fichier des profiles doit comporter une URL par ligne'
#        sys.exit()
# uncomment if you want to use privoxy + tor        
#    proxyIP = '127.0.0.1'
#    proxyPort = 8118
#
#    proxy_settings = {'network.proxy.type': 1,
#            'network.proxy.http': proxyIP,
#            'network.proxy.http_port': proxyPort,
#            'network.proxy.ssl': proxyIP,
#            'network.proxy.ssl_port':proxyPort,
#            'network.proxy.socks': proxyIP,
#            'network.proxy.socks_port':proxyPort,
#            'network.proxy.ftp': proxyIP,
#            'network.proxy.ftp_port':proxyPort 
#            }
#
#    with Browser('firefox',profile_preferences=proxy_settings) as browser:
#    with Browser() as browser:
    with Browser() as browser:

        browser.visit("https://twitter.com/")
        browser.execute_script('document.getElementById("signin-email").value = "'+username+'"')
        browser.execute_script('document.getElementById("signin-password").value = "'+password+'"')
        browser.find_by_css('button[type="submit"].submit.btn.primary-btn').click()
        try:
            file = open(txt, 'r')
        except:
            print "Impossible d'ouvrir le fichier"

        for line in file:
            try:
                url = re.match(r"https?://(www\.)?twitter\.com/intent/(#!/)?@?([^/\s]*)",line.strip())
                url = url.group()
                browser.visit(url)
                if not browser.is_element_present_by_css('.route-account_suspended'):
		    browser.find_by_css('a.fn.url.alternate-context').click()
                    browser.find_by_css('.user-dropdown').click()
                    browser.find_by_css('li.report-text button[type="button"]').click()
		    time.sleep(2)
#		    browser.choose('input[type="radio"][value="spam"]').click(1)
#		    browser.find_by_css('.input[type="radio"][value="spam"]')[1].click()
#		    browser.find_element_by_xpath(".//label")[1].click()
#		    browser.find_elements_by_css_selector('.input[type="radio"][value="spam"]')[1].click()
#		    browser.find_by_css('label.spam [type="radio"]').click()
#		    browser.choose("spam")[1].click()
#		    browser.find_elements_by_xpath(".//input[@type='radio' and @value='spam']")[0].click()
		    browser.find_by_css('button.btn.primary-btn.new-report-flow-next-button[type="button"]')[0].click()
		    time.sleep(2)
		    browser.find_by_css('button.btn.primary-btn.new-report-flow-done-button[type="button"]')[0].click()
#                   browser.find_by_css('button.btn.primary-btn:nth-child(1)').click()
                    followers = browser.find_by_css('a[data-nav="followers"] .ProfileNav-value').value;
                    msg = url.strip()
                    with open("log_reported_"+date+".txt", "a") as log:
                        log.write(msg+"\n")
                elif browser.is_element_present_by_css('.route-account_suspended'):
                    msg =  line.strip()+' - Suspended'
                    with open("log_suspended.txt", "a") as log:
                        log.write(msg+"\n")
                else:
                    msg = line.strip()+' - Unknown'
                    with open("log_unknown.txt", "a") as log:
                        log.write(msg+"\n")

                print msg

            except KeyboardInterrupt:
                print 'Quit by keyboard interrupt sequence !'
                break
            except HttpResponseError:
                msg = line.strip()+' - HttpResponseError'
                print msg
                with open("log_Error.txt", "a") as log:
                    log.write(msg+"\n")
		pass
            except:
                if line:
                    msg = url.strip()+' - CatchAllError'
                    print msg
                    with open("log_Error.txt", "a") as log:
                        log.write(msg+"\n")
                else:
                    pass

if __name__ == "__main__":
    try:
        main(sys.argv[1:])
    except KeyboardInterrupt:
        sys.stdout.write('\nQuit by keyboard interrupt sequence !')

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Twitter Reporter

Mon Nov 23, 2015 5:59 pm

You can try

sudo apt-get install iceweasel
sudo ln -s /usr/bin/firefox /usr/bin/iceweasel

but it probably won't work.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Twitter Reporter

Tue Nov 24, 2015 11:24 am

So far i know "firefox" is redirected to iceweasel automatically if iceweasel is installed.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Twitter Reporter

Tue Nov 24, 2015 12:12 pm

ghans wrote:So far i know "firefox" is redirected to iceweasel automatically if iceweasel is installed.

ghans
Perhaps the OP doesn't have iceweasel installed.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
rpdom
Posts: 17173
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Twitter Reporter

Tue Nov 24, 2015 7:19 pm

DougieLawson wrote:
ghans wrote:So far i know "firefox" is redirected to iceweasel automatically if iceweasel is installed.

ghans
Perhaps the OP doesn't have iceweasel installed.
In that case, what is the point in redirecting firefox to iceweasel?

Return to “Raspberry Pi OS”