<commit_before>import datetime
from bs4 import BeautifulSoup
import urllib2
import MySQLdb

last_second = -1
url = "http://localhost/sample.html"
time_gap = 5
t = 0
q = 0

def getData():
    page = urllib2.urlopen(url)
    soup = BeautifulSoup(page)
    pin1 = soup.text[soup.text.find("=")+1:soup.text.find("=")+4] 
    pin2 = soup.text[soup.text.rfind("=")+1:soup.text.rfind("=")+4]
    print "pin1 has "+pin1
    print "pin2 has "+pin2
    return (pin1,pin2)

def storeData(tup):
    # Open database connection
    db = MySQLdb.connect( "localhost","root","","smartbike" )

    # prepare a cursor object using cursor() method
    cursor = db.cursor()

    value1 = int(tup[0])
    value2 = int(tup[1])

    # Prepare SQL query to INSERT a record into the database.
    sql = "INSERT INTO `smartbike`.`master` (`ID`, `Name`, `Accident`) VALUES ('"+str(value1)+"', '"+str(value2)+"', '0');"
    
    try:
       # Execute the SQL command
       cursor.execute(sql)
       print "done"
       # Commit your changes in the database
       db.commit()
    except:
       # Rollback in case there is any error
       db.rollback()
       
    # disconnect from server
    db.close()

while(True):
    # infinite loop guys! :p
    current_seconds = int(datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')[17:])
    
    if( current_seconds%time_gap == 0 and last_second != current_seconds ):
        print current_seconds
        data = getData()
        storeData(data)
        last_second = current_seconds


    
<commit_msg>Fixed storing to db problem<commit_after>import datetime
from bs4 import BeautifulSoup
import urllib2
import MySQLdb

last_second = -1
url = "http://localhost/sample.html"
time_gap = 5
t = 0
q = 0

def getData():
    page = urllib2.urlopen(url)
    soup = BeautifulSoup(page)
    pin1 = soup.text[soup.text.find("=")+1:soup.text.find("=")+4] 
    pin2 = soup.text[soup.text.rfind("=")+1:soup.text.rfind("=")+4]
    print "pin1 has "+pin1
    print "pin2 has "+pin2
    return (pin1,pin2)
'''
def storeData(tup):
    # Open database connection
    db = MySQLdb.connect( "7cfcc050.ngrok.com","root","toor","smarthelmet" )

    # prepare a cursor object using cursor() method
    cursor = db.cursor()

    value1 = int(tup[0])
    value2 = int(tup[1])

    # Prepare SQL query to INSERT a record into the database.
    #sql = "INSERT INTO `smartbike`.`master` (`ID`, `Name`, `Accident`) VALUES ('"+str(value1)+"', '"+str(value2)+"', '0');"
    sql = "INSERT INTO `smarthelmet`.`a8122514058` (`date`, `time`, `rev`) VALUES ('a"+datetime.datetime.strftime(datetime.datetime.now(), '%d%m')+"', NOW(), '"+str(value1)+"');"
    print sql
    try:
       # Execute the SQL command
       cursor.execute(sql)
       print "done"
       # Commit your changes in the database
       db.commit()
    except:
       # Rollback in case there is any error
       db.rollback()
       
    # disconnect from server
    db.close()
'''

def storeData(tup):
    value1 = int(tup[0])
    value2 = int(tup[1])
    print "http://7cfcc050.ngrok.com/insert.php?name=8122514058&date="+datetime.datetime.strftime(datetime.datetime.now(), '%d%m')+"&rev="+str(value1)
    urllib2.urlopen("http://7cfcc050.ngrok.com/insert.php?name=8122514058&date="+datetime.datetime.strftime(datetime.datetime.now(), '%d%m')+"&rev="+str(value1))



while(True):
    # infinite loop guys! :p
    current_seconds = int(datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')[17:])
    
    if( current_seconds%time_gap == 0 and last_second != current_seconds ):
        print current_seconds
        data = getData()
        storeData(data)
        last_second = current_seconds


    

{'fraction_non_alphanumeric': 0.16022696568495, 'fraction_numerical': 0.02918130235071602, 'mean_word_length': 3.2551724137931033, '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': '7273969', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1274, 'n_words': 293}