<commit_before>from pypump import PyPump
from pypump import Client
from dateutil.parser import parse
from ConfigParser import SafeConfigParser
import twitter
import os.path

def simple_verifier(url):
	print 'Please follow the instructions at the following URL:'
	print url
	return raw_input("Verifier: ") # the verifier is a string

class PumpTweetParser:
	"""Parses the ini file and provides the results on demand."""

	# This file must exist in the current directory.
	filename = 'PumpTweet.ini'

	# Parses the ini file.
	def parse_ini(self):
		print 'Reading the config file...'

		# This verifies that the ini file exists.
		if not os.path.isfile(self.filename):
			message = self.filename + ' not found.'
			raise Exception(message)

		parser = SafeConfigParser()
		parser.read(self.filename)
		self._parser = parser
		self._recent = parser.get('history', 'recent')

		# Converts the date to a usable form.
		date = parser.get('history', 'published')
		self._published = parse(date)

		# Notes whether history exists in the ini file.
		self._history = len(date) > 0 and len(self._recent) > 0

	# Logs in to the Pump server.
	def pump_login(self):
		print 'Logging into the Pump server...'

		username = self._parser.get('pump', 'username')

		client = Client(
			webfinger = username,
			name = "Pump.io",
			type = "native")

		pump = PyPump(
			client = client,
			verifier_callback = simple_verifier)

		me = pump.Person(username)
		
		self._username = username
		self._pump = pump
		self._me = me

	# Logs in to Twitter.
	def twitter_login(self):
		print 'Logging into Twitter...'
		key = self._parser.get('twitter', 'key')
		secret = self._parser.get('twitter', 'secret')
		token = self._parser.get('twitter', 'token')
		token_secret = self._parser.get('twitter', 'token_secret')
		api = twitter.Api(
			consumer_key=key,
			consumer_secret=secret,
			access_token_key=token,
			access_token_secret=token_secret
		)
		
		self._api = api

	def __init__(self):
		self.parse_ini()
		self.pump_login()
		self.twitter_login()

	# Writes the latest update Pump ID in the ini file.
	# Be careful when changing this.  It rewrites the ini file.
	def update_recent(self, latest, published):<commit_msg>Adding better error message for unreachable servers.<commit_after>import os.path
import sys
import twitter
from pypump import PyPump
from pypump import Client
from dateutil.parser import parse
from ConfigParser import SafeConfigParser
from requests.exceptions import ConnectionError

def simple_verifier(url):
	print 'Please follow the instructions at the following URL:'
	print url
	return raw_input("Verifier: ") # the verifier is a string

class PumpTweetParser:
	"""Parses the ini file and provides the results on demand."""

	# This file must exist in the current directory.
	filename = 'PumpTweet.ini'

	# Parses the ini file.
	def parse_ini(self):
		print 'Reading the config file...'

		# This verifies that the ini file exists.
		if not os.path.isfile(self.filename):
			message = self.filename + ' not found.'
			raise Exception(message)

		parser = SafeConfigParser()
		parser.read(self.filename)
		self._parser = parser
		self._recent = parser.get('history', 'recent')

		# Converts the date to a usable form.
		date = parser.get('history', 'published')
		self._published = parse(date)

		# Notes whether history exists in the ini file.
		self._history = len(date) > 0 and len(self._recent) > 0

	# Logs in to the Pump server.
	def pump_login(self):
		print 'Logging into the Pump server...'

		username = self._parser.get('pump', 'username')

		client = Client(
			webfinger = username,
			name = "Pump.io",
			type = "native")

		try:
			pump = PyPump(
				client = client,
				verifier_callback = simple_verifier)
		except ConnectionError, e:
			print 'Error: Unable to connect to server for ' + username + '.'
			print e
			sys.exit()

		me = pump.Person(username)
		
		self._username = username
		self._pump = pump
		self._me = me

	# Logs in to Twitter.
	def twitter_login(self):
		print 'Logging into Twitter...'
		key = self._parser.get('twitter', 'key')
		secret = self._parser.get('twitter', 'secret')
		token = self._parser.get('twitter', 'token')
		token_secret = self._parser.get('twitter', 'token_secret')
		api = twitter.Api(
			consumer_key=key,
			consumer_secret=secret,
			access_token_key=token,
			access_token_secret=token_secret
		)
		
		self._api = api

	def __init__(self):
		self.parse_ini()
		self.pump_login()
		self.twitter_login()

	# Writes the latest update Pump ID in the ini file.
	# Be careful when changing this.  It rewrites the ini file.
	def update_recent(self, latest, published):
{'fraction_non_alphanumeric': 0.1053085886922745, 'fraction_numerical': 0.0008631851532153647, 'mean_word_length': 3.8331595411887385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3182087', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1424, 'n_words': 469}