Posts for: #Twitter

Social Justice as Financial Leverage

Before you dig into this stupid rant, make sure you read this report. If you haven’t read it, you won’t understand what the fuck I’m talking about.

The latest slam page written by Hindenburg Research is about Jack Dorsey’s predatory credit and payment companies. It’s a well-written and concise report with testimony from former employees of Block. This report goes above and beyond statements of facts about why a company may go solvent. It actually points to strategic and valid reasons a company should go solvent based on the impact it has on society. Honestly, I see this is an entirely new field of short-selling and I find it fascinating.

[]

Twitter OSINT Strategies

My current tweet dumper iteration dumps everything collected into a flat file. That’s fine for intermittent use, but won’t do much good when we eventually get into the “big leagues” and start grabbing at streams of data that will include above and beyond 3200 tweets. Flat files will quickly swell to sizes that are no longer manageable.

Wat do.

Well, there are hundreds of “database backend” options. Literally hundreds. We’re inevitably going to be storing tweets from various sources with multiple goals in mind. A veritable forest of *.csv files doesn’t neatly organize our data. SQLite3 will provide the backend. It’s local, zero configuration required, and we can concentrate all our information into a single file with multiple tables.

[]

Ruby Tweet Scraper v.02

I’ve made improvements to the tweet dumper. Added geo information. Also added progress bar, so check gem requirements.

#!/bin/env ruby
# encoding: utf-8

require 'twitter'
require 'csv'
require 'progressbar'

client = Twitter::REST::Client.new do |config|
	config.consumer_key = "YoursHere"
	config.consumer_secret = "YoursHere"
	config.access_token = "YoursHere"
	config.access_token_secret = "YoursHere"
end

scrname = String.new ARGV[0]

def collect_with_max_id(collection=[], max_id=nil, &block)
  response = yield(max_id)
  collection += response
  response.empty? ? collection.flatten : collect_with_max_id(collection, response.last.id - 1, &block)
end

def client.get_all_tweets(user)
  twtcount = user(user).statuses_count
  if twtcount > 3200
      twtcount = 3200 / 200
  else
      twtcount = twtcount / 200
  end
  pbar = ProgressBar.new("Downloading", twtcount)
  collect_with_max_id do |max_id|
    pbar.inc
    options = {:count => 200, :include_rts => true}
    options[:max_id] = max_id unless max_id.nil?
    user_timeline(user, options)
  end
end

junk = client.get_all_tweets(scrname)

CSV.open("#{scrname}.csv", "w") do |csv|
	junk.each do |tweet|
		csv << [tweet.id, tweet.created_at, tweet.user.screen_name, tweet.text, tweet.source, tweet.geo]
	end
end

I don’t comment. Sorry. I guess I can go back through and comment where it’s helpful and repost another time. It works with Ruby 1.9.2 anyways.

[]

Ruby Twitter Scraper

Requires the twitter gem. Install it as per usual. Code as follows:

#!/bin/env ruby
# encoding: utf-8

require 'twitter'
require 'csv'

client = Twitter::REST::Client.new do |config|
	config.consumer_key = "insert"
	config.consumer_secret = "insert"
	config.access_token = "insert"
	config.access_token_secret = "insert"
end

def collect_with_max_id(collection=[], max_id=nil, &block)
  response = yield(max_id)
  collection += response
  response.empty? ? collection.flatten : collect_with_max_id(collection, response.last.id - 1, &block)
end

def client.get_all_tweets(user)
  collect_with_max_id do |max_id|
    options = {:count => 200, :include_rts => true}
    options[:max_id] = max_id unless max_id.nil?
    user_timeline(user, options)
  end
end

junk = client.get_all_tweets(ARGV[0])

CSV.open("#{ARGV[0]}.csv", "w") do |csv|
	junk.each do |tweet|
		csv << [tweet.id, tweet.created_at, tweet.user.screen_name, tweet.text, tweet.source, tweet.geo]
	end
end

Excellent. I’m going to revise it as necessary, but it’s a most effective scraper. Though I’d love to add some sort of progress bar to it, haven’t succeeded in that yet. I’ll keep you posted and update it as the iterations of this thing change. It was smashed together from the twitter gem’s bare scraper and CSV output added. I’m quite pleased. Going to also consider adding time and date statistics compilation. I might just write an entirely separate script for that. Not sure yet.

[]

Joseph A. Camp, #Hostage68

Jojo’s PO contact info via @5hm00p

Attention to everyone who was harassed or threatened by Joseph Camp:

I just got word that his sentencing is Tuesday, and he's going to he
served 5 months and when he's out he's free to do as he pleases. I
myself don't believe this is someone who belongs in a normal functioning
society, therefore a few of us have started a campaign to get him some
sort of supervision when he is released. How can you help?
Simple....write to:

US Parole Officer George Martin
100 State St.
Rochester, NY 14614

or

you can reach him by phone at (585) 666-5901


and tell him about your encounter with this maniac. The last thing we
want is him around again harassing people for Sue Basko (don't worry,
disbar comin) again and invading people's lives and their privacy. This
is your chance to put a completely horrible human being away and
hopefully make him learn his lesson.
[]

Putting It All Together

Grab the mention counter. Grab the tweet scraper. Point it at four or five “known” associated targets and grab 3k tweets at regular expected intervals. Better yet, use tweepy to regularly grab tweets as they’re sent. Amass a good amount. Once you’ve amassed a good amount of tweets, fire up the mention counter. Make your cutoff large. Make it count.

Fire up Gephi and open your CSV in it. It should automatically generate an interesting map. Use the heat map feature to get even more interesting results. Be amazed that you can OSINT. Most of all, have fun.

[]

Ruby Twitter Mention Counter

Ruby is like the Visual Basic of the scripting world. You can do simple shit in ten lines of code or less. After experimentation, googling, and satisfaction of curiosity I’ve sated myself with a simple counterpart to my python tweet dumper.

Two arguments. Twitter screen name and cutoff for number of mentions. It’s useful to see your data in a new way. I’m going to take it further pretty soon, processing date information to squeeze every bit of usefulness out of it.

[]

Tweet Scraper in Python

Code first, talk later.

#!/usr/bin/env python
# encoding: utf-8
 
import tweepy #https://github.com/tweepy/tweepy
import unicodecsv
import sys
 
#Twitter API credentials
consumer_key = ""
consumer_secret = ""
access_key = ""
access_secret = ""
 
 
def get_all_tweets(screen_name):
	#Twitter only allows access to a users most recent 3240 tweets with this method
	
	#authorize twitter, initialize tweepy
	auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
	auth.set_access_token(access_key, access_secret)
	api = tweepy.API(auth)
	
	#initialize a list to hold all the tweepy Tweets
	alltweets = []	
	
	#make initial request for most recent tweets (200 is the maximum allowed count)
	new_tweets = api.user_timeline(screen_name = screen_name,count=200)
	
	#save most recent tweets
	alltweets.extend(new_tweets)
	
	#save the id of the oldest tweet less one
	oldest = alltweets[-1].id - 1
	
	#keep grabbing tweets until there are no tweets left to grab
	while len(new_tweets) > 0:
		print "getting tweets before %s" % (oldest)
		
		#all subsiquent requests use the max_id param to prevent duplicates
		new_tweets = api.user_timeline(screen_name = screen_name,count=200,max_id=oldest)
		
		#save most recent tweets
		alltweets.extend(new_tweets)
		
		#update the id of the oldest tweet less one
		oldest = alltweets[-1].id - 1
		
		print "...%s tweets downloaded so far" % (len(alltweets))
	
	#transform the tweepy tweets into a 2D array that will populate the csv	
	outtweets = [[tweet.id_str, tweet.created_at, tweet.text.encode('utf-8'), tweet.geo, tweet.source] for tweet in alltweets]
	
	#write the csv	
	with open('%s_tweets.csv' % screen_name, 'wb') as f:
		writer = unicodecsv.writer(f)
		writer.writerow(["id","created_at","text","geo","source"])
		writer.writerows(outtweets)
	
	pass
 
 
if __name__ == '__main__':
	#pass in the username of the account you want to download
	get_all_tweets(sys.argv[1])

The entirety of this script doesn’t belong to me at all. My only contribution is fixing utf-8 issues. Requires tweepy and unicodecsv. Outputs tweets in a comma-delimited text file.

[]