<commit_before>#!/usr/bin/env python

from textwrap import TextWrapper

import uuid
import ConfigParser
import pymongo
from twython import TwythonStreamer

class EumssiStreamer(TwythonStreamer):
  status_wrapper = TextWrapper(width=60, initial_indent='    ', subsequent_indent='    ')
  mongo_client = pymongo.MongoClient()
  db = mongo_client['eumssi_test']
  col = db['content_items']

  def on_success(self, status):
    ''' write tweet to MongoDB '''
    try:
      twuid = uuid.uuid4()
      try:
        print self.status_wrapper.fill(status['text'])
        print '\n %s  %s  via %s\n' % (status['user']['screen_name'], status['created_at'], status['source'])
      except Exception as e:
        print e
      print "inserted: ", self.col.insert({'_id':uuid.uuid4(),'source':'Twitter','source_meta':{'original':status}})
    except Exception as e:
      print e

  def on_error(self, status_code, data):
    '''
    just keep going when something fails
    should handle errors somehow (reconnect?)
    '''
    print 'An error has occured! Status code = %s' % status_code<commit_msg>added source format field<commit_after>#!/usr/bin/env python

from textwrap import TextWrapper

import uuid
import ConfigParser
import pymongo
from twython import TwythonStreamer

class EumssiStreamer(TwythonStreamer):
  status_wrapper = TextWrapper(width=60, initial_indent='    ', subsequent_indent='    ')
  mongo_client = pymongo.MongoClient()
  db = mongo_client['eumssi_test']
  col = db['content_items']

  def on_success(self, status):
    ''' write tweet to MongoDB '''
    try:
      twuid = uuid.uuid4()
      try:
        print self.status_wrapper.fill(status['text'])
        print '\n %s  %s  via %s\n' % (status['user']['screen_name'], status['created_at'], status['source'])
      except Exception as e:
        print e
      print "inserted: ", self.col.insert({'_id':uuid.uuid4(),'source':'Twitter','source_meta':{'original':status, 'format':'twitter-api-1.1'}})
    except Exception as e:
      print e

  def on_error(self, status_code, data):
    '''
    just keep going when something fails
    should handle errors somehow (reconnect?)
    '''
    print 'An error has occured! Status code = %s' % status_code
{'fraction_non_alphanumeric': 0.13186318631863186, 'fraction_numerical': 0.004500450045004501, 'mean_word_length': 3.832608695652174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5609381', 'n_tokens_mistral': 707, 'n_tokens_neox': 693, 'n_words': 181}