<commit_before>import feedparser 
import tweepy 
import store
import time
from datetime import datetime
import psycopg2
import urllib.parse

def tweet(new_entries, publication_name):
	for new_entry in new_entries:

		entry_hashtags = new_entry[1]
		entry_url = new_entry[0] # e.g. https://medium.com/p/99099da313b5

		tweet_msg = entry_hashtags + " " + entry_url

		try:
			api.update_status(tweet_msg)

			# insert entry in db 
			entry_id = entry_url[21:] # e.g. 99099da313b5
			entry_published_date = new_entry[2]
			db_insert_entry(entry_id, entry_published_date, publication_name)
			
		except tweepy.error.TweepError as e:
			print(e.response.text)
			print(entry_id)

def manipulate_entry_tags(tags):
	hashtags = ""
	for tag in tags:
		"""
		tag is in form : {'label': None, 'scheme': None, 'term': 'web-development'} 
		Extract term only and replace "-" if exists with "_"
		"""
		hashtag = tag.term
		if(hashtag.find('-') != -1):
			hashtag = str.replace(hashtag, "-", "_")
		hashtags += "#" + hashtag + " "
	return hashtags

def handle_entries(entries, publication_name):
	new_entries = []
	for entry in entries:
		cur = db_con.cursor()

		# cleaning date for db insert 
		entry_published_date = str.replace(entry.published, ' GMT', '')
		formated_publication_dt = datetime.strptime(entry_published_date, '%a, %d %b %Y %H:%M:%S')

		# check if entry retrieved already exists
		cur.execute(select_statment,(entry.id[21:],))<commit_msg>Refactor code for better readability<commit_after>import feedparser 
import tweepy 
import store
import time
from datetime import datetime
import psycopg2
import urllib.parse

def tweet(new_entries, publication_name):
	for new_entry in new_entries:

		entry_hashtags = new_entry[1]
		entry_url = new_entry[0] # e.g. https://medium.com/p/99099da313b5
		entry_id = entry_url[21:] # e.g. 99099da313b5

		tweet_msg = entry_hashtags + " " + entry_url

		try:
			api.update_status(tweet_msg)

			# insert entry in db 
			entry_published_date = new_entry[2]
			db_insert_entry(entry_id, entry_published_date, publication_name)
			
		except tweepy.error.TweepError as e:
			print(e.response.text)
			print(entry_id)

def manipulate_entry_tags(tags):
	hashtags = ""
	for tag in tags:
		"""
		tag is in form : {'label': None, 'scheme': None, 'term': 'web-development'} 
		Extract term only and replace "-" if exists with "_"
		"""
		hashtag = tag.term
		if(hashtag.find('-') != -1):
			hashtag = str.replace(hashtag, "-", "_")
		hashtags += "#" + hashtag + " "
	return hashtags

def handle_entries(entries, publication_name):
	new_entries = []
	for entry in entries:
		cur = db_con.cursor()

		# cleaning date for db insert 
		entry_published_date = str.replace(entry.published, ' GMT', '')
		formated_publication_dt = datetime.strptime(entry_published_date, '%a, %d %b %Y %H:%M:%S')

		# check if entry retrieved already exists
		cur.execute(select_statment,(entry.id[21:],))
{'fraction_non_alphanumeric': 0.12302405498281786, 'fraction_numerical': 0.018556701030927835, 'mean_word_length': 4.331501831501831, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '5459935', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1034, 'n_words': 243}