<commit_before>import re
import praw
import time
import MySQLdb
import OpenSSL
import tvdb_api
import tvdb_exceptions
import requests

from configparser import ConfigParser

tvshow = "seinfeld"

t = tvdb_api.Tvdb()

r = praw.Reddit("browser-based:SeinfeldEpsisode Script:v1.0 (by /u/HeadlessChild)")

### LOGIN ###
config = ConfigParser()
config.read("login.txt")

username = config.get("Reddit", "Username")
password = config.get("Reddit", "Password")

r.login(username, password, disable_warning=True)
############

### DATABASE ###
db_username = config.get("MySQL", "Username")
db_password = config.get("MySQL", "Password")
db = MySQLdb.connect(host="localhost",
					 user=db_username,
					 passwd=<PASSWORD>,
					 db="reddit_comments")
cur = db.cursor()

cur.execute('CREATE TABLE IF NOT EXISTS comments(ID TEXT)')
db.commit()
############

pattern1 = re.compile(r"""(?:s|season)(?:\s)(?P<s>\d+)(?:.*)(?:e|x|episode|\n)(?:\s)(?P<ep>\d+)""", re.VERBOSE)
pattern2 = re.compile(r"""(?:s|season)(?P<s>\d+)(?:e|x|episode|\n)(?:\s)(?P<ep>\d+)""", re.VERBOSE)
pattern3 = re.compile(r"""(?:s|season)(?:\s)(?P<s>\d+)(?:e|x|episode|\n)(?P<ep>\d+)""", re.VERBOSE)
pattern4 = re.compile(r"""(?:s|season)(?P<s>\d+)(?:e|x|episode|\n)(?P<ep>\d+)""", re.VERBOSE)
pattern5 = re.compile(r"""(?:s|season)(?P<s>\d+)(?:.*)(?:e|x|episode|\n)(?P<ep>\d+)""", re.VERBOSE)
pattern6 = re.compile(r"""(?:s|season)(?:\s)(?P<s>\d+)(?:.*)(?:e|x|episode|\n)(?P<ep>\d+)""", re.VERBOSE)
pattern7 = re.compile(r"""(?:s|season)(?P<s>\d+)(?:.*)(?:e|x|episode|\n)(?:\s)(?P<ep>\d+)""", re.VERBOSE)

patterns = [pattern1, pattern2, pattern3, pattern4, pattern5, pattern6, pattern7 ]

def run_bot():
	subreddit = r.get_subreddit("seinfeld")
	comments = subreddit.get_comments(limit=512)
	for comment in comments:
		comment_text = comment.body.lower()
		for p in patterns:
			m = re.search(p, comment_text)
			ID = comment.id
			cur.execute('SELECT * FROM comments WHERE ID=(%s)', [ID])
			result = cur.fetchone()
			if m and not result and str(comment.author) != str(username):
				try:
					try:
						episode_info = t[tvshow][int(m.group('s'))][int(m.group('ep'))]
						comment.reply('**Seinfeld: Season '+m.group('s')+' Episode '+m.group('ep')+'**'+\
									  '\n___\n'\
									  '\n\n**Episode Name:** '+episode_info['episodename']+\
									  '\n\n**Overview:** '+episode_info['overview']+\
									  '\n\n**Director:** '+episode_info['director']+\
									  '\n\n**Writer(s):** '+episode_info['writer']+\
									  '\n\n**First Aired:** '+episode_info['firstaired']+\
									  '\n\n**Rating:** '+episode_info['rating']+\
									  '\n___\n'\
									  '^| ^Hi! ^I\'m ^a ^bot ^for ^the ^subreddit [^/r/seinfeld](https://www.reddit.com/r/seinfeld) '\
									  '^| [^Help ^me ^improve!](https://github.com/HeadlessChild/reddit-episode-bot) '\<commit_msg>Fixes the bug for #1 regarding regex patterns<commit_after>import re
import praw
import time
import MySQLdb
import OpenSSL
import tvdb_api
import tvdb_exceptions
import requests

from configparser import ConfigParser

tvshow = "seinfeld"

t = tvdb_api.Tvdb()

r = praw.Reddit("browser-based:SeinfeldEpsisode Script:v1.0 (by /u/HeadlessChild)")

### LOGIN ###
config = ConfigParser()
config.read("login.txt")

username = config.get("Reddit", "Username")
password = config.get("Reddit", "Password")

r.login(username, password, disable_warning=True)
############

### DATABASE ###
db_username = config.get("MySQL", "Username")
db_password = config.get("MySQL", "Password")
db = MySQLdb.connect(host="localhost",
					 user=db_username,
					 passwd=db_password,
					 db="reddit_comments")
cur = db.cursor()

cur.execute('CREATE TABLE IF NOT EXISTS comments(ID TEXT)')
db.commit()
############

pattern1 = re.compile(r"""(?:(\ss)|season)(?:\s)(?P<s>\d+)(?:.*)(?:(\se)|x|episode|\n)(?:\s)(\d+)""", re.VERBOSE)
pattern2 = re.compile(r"""(?:(\ss)|season)(?P<s>\d+)(?:(\se)|(\sx)|episode|\n)(?:\s)(?P<ep>\d+)""", re.VERBOSE)
pattern3 = re.compile(r"""(?:(\ss)|season)(?:\s)(?P<s>\d+)(?:(\se)|(\sx)|episode|\n)(?P<ep>\d+)""", re.VERBOSE)
pattern4 = re.compile(r"""(?:(\ss)|season)(?P<s>\d+)(?:(\se)|(\sx)|episode|\n)(?P<ep>\d+)""", re.VERBOSE)
pattern5 = re.compile(r"""(?:(\ss)|season)(?P<s>\d+)(?:.*)(?:(\se)|(\sx)|episode|\n)(?P<ep>\d+)""", re.VERBOSE)
pattern6 = re.compile(r"""(?:(\ss)|season)(?:\s)(?P<s>\d+)(?:.*)(?:(\se)|(\sx)|episode|\n)(?P<ep>\d+)""", re.VERBOSE)
pattern7 = re.compile(r"""(?:s|season)(?P<s>\d+)(?:.*)(?:(\se)|(\sx)|episode|\n)(?:\s)(?P<ep>\d+)""", re.VERBOSE)
pattern8 = re.compile(r"""(?:s|season)(?P<s>\d+)(?:e|x|episode|\n)(?P<ep>\d+)(?:.*)""", re.VERBOSE)
pattern9 = re.compile(r"""(?:s|season)(?:\s)(?P<s>\d+)(?:e|x|episode|\n)(?:\s)(?P<ep>\d+)""", re.VERBOSE)
pattern10 = re.compile(r"""(?:s|season)(?P<s>\d+)(?:e|x|episode|\n)(?:\s)(?P<ep>\d+)""", re.VERBOSE)
pattern11 = re.compile(r"""(?:s|season)(?:\s)(?P<s>\d+)(?:e|x|episode|\n)(?P<ep>\d+)""", re.VERBOSE)

pattern12 = re.compile(r"""(?:(\se)|x|episode|\n)(?:\s)(?P<ep>\d+)(?:.*)(?:(\ss)|season)(?:\s)(?P<s>\d+)""", re.VERBOSE)
pattern13 = re.compile(r"""(?:(\se)|x|episode|\n)(?P<ep>\d+)(?:(\ss)|season)(?:\s)(?P<s>\d+)""", re.VERBOSE)
pattern14 = re.compile(r"""(?:(\se)|x|episode|\n)(?:\s)(?P<ep>\d+)(?:(\ss)|season)(?P<s>\d+)""", re.VERBOSE)
pattern16 = re.compile(r"""(?:(\se)|x|episode|\n)(?P<ep>\d+)(?:(\ss)|season)(?P<s>\d+)""", re.VERBOSE)
pattern17 = re.compile(r"""(?:(\se)|x|episode|\n)(?P<ep>\d+)(?:.*)(?:(\ss)|season)(?P<s>\d+)""", re.VERBOSE)
pattern18 = re.compile(r"""(?:(\se)|x|episode|\n)(?:\s)(?P<ep>\d+)(?:.*)(?:(\ss)|season)(?P<s>\d+)""", re.VERBOSE)
pattern19 = re.compile(r"""(?:(\se)|x|episode|\n)(?P<ep>\d+)(?:.*)(?:s|season)(?:\s)(?P<s>\d+)""", re.VERBOSE)
pattern20 = re.compile(r"""(?:e|x|episode|\n)(?P<ep>\d+)(?:s|season)(?P<s>\d+)""", re.VERBOSE)
pattern21 = re.compile(r"""?:e|x|episode|\n)(?:\s)(?P<ep>\d+)(?:s|season)(?:\s)(?P<s>\d+)""", re.VERBOSE)
pattern22 = re.compile(r"""(?:e|x|episode|\n)(?P<ep>\d+)(?:s|season)(?:\s)(?P<s>\d+)""", re.VERBOSE)
pattern23 = re.compile(r"""(?:e|x|episode|\n)(?:\s)(?P<ep>\d+)(?:s|season)(?P<s>\d+)""", re.VERBOSE)

patterns = [pattern1, pattern2, pattern3, pattern4, pattern5, pattern6, pattern7, pattern8, pattern9, pattern10, pattern11, pattern12,
pattern13, pattern14, pattern15, pattern16, pattern17, pattern18, pattern19, pattern20, pattern21, pattern22, pattern23 ]

def run_bot():
	subreddit = r.get_subreddit("seinfeld")
	comments = subreddit.get_comments(limit=512)
	for comment in comments:
		comment_text = comment.body.lower()
		for p in patterns:
			m = re.search(p, comment_text)
			ID = comment.id
			cur.execute('SELECT * FROM comments WHERE ID=(%s)', [ID])
			result = cur.fetchone()
			if m and not result and str(comment.author) != str(username):
				try:
					try:
						episode_info = t[tvshow][int(m.group('s'))][int(m.group('ep'))]
						comment.reply('**Seinfeld: Season '+m.group('s')+' Episode '+m.group('ep')+'**'+\
									  '\n___\n'\
									  '\n\n**Episode Name:** '+episode_info['episodename']+\
									  '\n\n**Overview:** '+episode_info['overview']+\
									  '\n\n**Director:** '+episode_info['director']+\
									  '\n\n**Writer(s):** '+episode_info['writer']+\
									  '\n\n**First Aired:** '+episode_info['firstaired']+\
									  '\n\n**Rating:** '+episode_info['rating']+\
									  '\n___\n'\
									  '^| ^Hi! ^I\'m ^a ^bot ^for ^the ^subreddit [^/r/seinfeld](https://www.reddit.com/r/seinfeld) '\
									  '^| [^Help ^me ^improve!](https://github.com/HeadlessChild/reddit-episode-bot) '\
{'fraction_non_alphanumeric': 0.3015115354017502, 'fraction_numerical': 0.012861309997348183, 'mean_word_length': 5.177723177723178, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4687627', 'n_tokens_mistral': 3459, 'n_tokens_neox': 3139, 'n_words': 400}