def run(self): connection = DataBase().connection() cursor = connection.cursor() # cursor.execute("truncate moviesfyi_stage.bk_movies") connection.commit() cursor.execute(DataBase().showtimesCountQuery) count = cursor.fetchall() count = count[0][0] print "data==", count limit = 1 start = 1 stop = 300 loopCount = 300 try: limit = count / loopCount except: limit = 15 pass print "no of threads==", limit + 1 for i in range(0, limit + 1): t = threading.Thread(target=self.bms_movie_count, args=("thread_name_" + str(i), start, stop)) t.start() start = stop + 1 stop = start + loopCount - 1 try: connection.close() print "Initial Connection Closed" except: print "Initial connection Not closed"
def run(self): connection = DataBase().connection() cursor = connection.cursor() cursor.execute(DataBase().trunk_ticket_info) connection.commit() cursor.execute(DataBase().ssidcountquery) count = cursor.fetchall() count = count[0][0] print "data==", count limit = 1 start = 0 stop = 100 loopCount = 100 try: limit = count / loopCount except: limit = 15 pass print "no of threads==", limit + 1 for i in range(0, limit + 1): t = threading.Thread(target=self.bms_ssid_count, args=("thread_name_" + str(i), start, stop)) t.start() start = start + 100 stop = 100 try: connection.close() print "Initial Connection Closed" except: print "Initial connection Not closed"
def run(self): connection = DataBase().connection() cursor = connection.cursor() cursor.execute("truncate collections.bms_showtimes") connection.commit() print DataBase().showtimesCountQuery cursor.execute(DataBase().showtimesCountQuery) count = cursor.fetchall() count = count[0][0] limit = 1 start = 1 stop = 2000 loopCount = 2000 try: limit = count / loopCount except: limit = 15 pass for i in range(0, limit + 1): t = threading.Thread(target=self.bms_showtime_count, args=("thread_name_" + str(i), start, stop)) t.start() start = stop + 1 stop = start + loopCount - 1 try: connection.close() print "Initial Connection Closed" except: print "Initial connection Not closed"
def ticketsinfo(self, starts, stops): connection = DataBase().connection() cursor = connection.cursor() date = datetime.date.today() date = str(date) date = date.replace("-", "") query = "" # print date seats_ssid = "SELECT theater_code ,showdate,showtime,sessionid FROM collections.bms_showtimes where showdate =CURDATE() AND STR_TO_DATE(showtime,'%l:%i %p') BETWEEN SUBTIME(ADDTIME(current_time(),'5:30:00.00'),5900) AND ADDTIME(ADDTIME(current_time(),'5:30:00.00'),5900) group by sessionid limit " + str( starts) + " , " + str(stops) print seats_ssid cursor.execute(seats_ssid) results = cursor.fetchall() # print "length======================================================================================",len(results) for j in results: print j[0] url = "https://in.bookmyshow.com/serv/getData?cmd=GETSHOWINFO&vid=" + j[ 0] + "&ssid=" + str(j[3]) print url r = requests.get(url) data = r.text val = "" myjson = json.loads(data.replace("arrShowInfo=", "")[:-1]) # print "length==",len(myjson) for mjson in range(len(myjson)): try: tid = myjson[mjson][0] ssid = myjson[mjson][1] tc_class = myjson[mjson][2] t_class = myjson[mjson][3] price = myjson[mjson][4] screen_name = myjson[mjson][33] m = myjson[mjson].index(date) l = myjson[mjson][m:] totalseats = l[2] availableseats = l[3] val = val + "('" + tid + "','" + screen_name + "'," + "'" + ssid + "'," + "'" + tc_class + "'," + "'" + t_class + "'," + "'" + price + "'," + "'" + totalseats + "'," + "'" + availableseats + "')," except: "DNA" val = val[:-1] query = DataBase().seats_info + val # print query try: cursor.execute(query) connection.commit() if cursor.lastrowid: print('last insert id', cursor.lastrowid) else: print('last insert id not found') connection.commit() except: print query
def save_movie(self, nombre: Movie): # ----> Busca una película movie_new = APIMovie().getMovie(nombre) #if movie_new == None: #print("No existe") #else: DataBase().saveMovie(movie_new) #Guardar en la base de datos
def search_movie(self, name:str): # ----> Busca una película y pregunta si quiere guardar #movie_new = APIMovie().getMovie(name) movie_titles = APIMovie().get_movie_titles(name) if movie_titles == None: print("No se encontro la informacion") else: print("Se encontraon los siguientes resultados: \n") for i in range(len(movie_titles)): print(movie_titles[i]) n = False while n == False: print("¡¡Mi loco!!, escoge el nombre de una película y vuelve a hacer la busqueda sí quieres guardarla :D\n") op = int(input("Teclea 1 para hacer la busqueda de nuevo y guardarla Ó teclea 2 para regresar al menu:\n")) if op == 1: new_name = str(input("Cual fue la película que escogiste? \n")) new_search = APIMovie().getMovie(new_name) #Se crea el objeto con la película nueva DataBase().saveMovie(new_search) #Guardar en la base de datos print("Pelicula guardada, hasta luego :D") n = True elif op == 2: n = True #print("Al menu") else: print("Elige una opcion del menu")
def getBmsShowTimes(self, starts, stops): connection = DataBase().connection() cursor = connection.cursor() sql = "SELECT id,theater_url from collections.bms_theaters where theater_url is not null and id between " + str( starts) + " and " + str(stops) cursor.execute(sql) results = cursor.fetchall() date = datetime.date.today() date = str(date) date = date.replace("-", "") movies_ins = "" count = 0 for j in results: testurl = j[1] url = j[1] da = "https://in.bookmyshow.com" url = da + url r = requests.get(url) data = r.text soup = BeautifulSoup(data) query = "" list = "" for list in soup.find_all('a', href="javascript:;"): try: list = list['onclick'] if ("blnVistaCine" in list): list = list list = list.split("callSeatLayout(") teatinfo = list[1].split(")") teatinfo = teatinfo[0].split(",") theater_code = teatinfo[0] sessionid = teatinfo[1] movie_code = teatinfo[2] showtime = teatinfo[3] date = date query = query + "(" + movie_code + ",''," + theater_code + ",''," + "'y','" + date + "'," + showtime + "," + "'y'," + sessionid + ")," except: "" query = query[:-1] insquery = DataBase().show_time_ssid + query try: cursor.execute(insquery) connection.commit() except: "" connection.close()
def returnPrediction(nameCompany): ticker = companyTicker[nameCompany] database = DataBase() toreturn = {} toreturn['prediction'] = database.getPredictedClose(ticker) return toreturn
def __init__(self, vk_session, event, keyboard): self.db = DataBase(data.database['host'], data.database['username'], data.database['password'], data.database['database'], data.database['port']) self.vk_api = vk_session self.event = event self.cursor, self.connection = self.db.connect() self.keyboard = keyboard
def show_a_movie(self, name:str): # ----> Muestra una película que esta guardada en la BDD moviesList = DataBase().showMovie(name) #if moviesList == "" or moviesList == None: #if name Not in movielist # print("No existe esta película en la base de datos :(\n") #else: #print("Película encontrada: \n") #for item in moviesList: # print(item) # print("\n") print(moviesList)
def show_all_movies(self): # ----> Muestra todas las películas guardadas en la BDD moviesList = DataBase().showAllMovies() #if moviesList == "" or moviesList == None: # print("Aún no hay datos guardados") #else: #print("Películas guardadas: \n") #for item in moviesList: # print(item) # print("\n") print( moviesList)
class MyTest(unittest.TestCase): myScraper = Scraper() myDb = DataBase('avatar.db') collectordb = CollectorDB('collector.db') imageCorrection = ImageCorrection() edge_detection = EdgeDetection() image_warper = ImageWarper() image_hasher = ImageHasher() test_image = cv2.imread("warped.jpg") second_test = cv2.imread("ow.jpg") def test(self): # test collector string self.assertEqual(self.collectordb.check_game("Grand Theft Auto V"), "Grand Theft Auto V") # second test self.assertNotEqual(self.collectordb.check_game("Grand Theft Auto V"), "Tekken 7") # checking hamming distance calculation self.assertEqual( self.myDb.ham_dst("2d2ec9e064603833", "2d2ec9e064603833"), 0) self.assertEqual( self.myDb.ham_dst("2d2bf9e56460f833", "2d2ec9e064603836"), 5) # no two images should have same hash self.assertEqual(self.image_hasher.generate_hash(self.test_image), "2f6c71b19336322a") self.assertNotEqual(self.image_hasher.generate_hash(self.second_test), "2f6c71b19336322a") # retrieving from db should always be a list self.assertIsInstance(self.myDb.fetch_hash("2d2ec9e064603836"), list) # cv2 should return images self.assertIsInstance(self.edge_detection.canny_edge(self.second_test), np.ndarray) self.assertTrue( self.myDb.ham_dst("9897f4b0f0cc0ef8", "dd9237b0704c4ed9"))
def delete_movie(self, name): # ----> Borra una película que esta guardada en la BDD by ID moviesList = DataBase().deleteMovie(name)
# The script is supposed to be run by daemon to collect the weather data for the city from ApiClient import ApiClient from config import CONFIG from Database import DataBase from models.City import City from models.Weather import Weather from utils import unix_to_datetime import json db = DataBase() db.generate() def request_weather(city): apiClienet = ApiClient(CONFIG['appid'], city.city_id) response = apiClienet.weather() response = json.loads(response.text) # Save weather to DB if entry for this time does not exist if len(Weather.get_by_unix(response['dt'])) == 0: weather_entry = Weather.save(city_id=city.city_id, desc=response['weather'][0]['main'], temp_max=response['main']['temp_max'], temp_min=response['main']['temp_min'], pressure=response['main']['pressure'], humidity=response['main']['humidity'], visibility=response['visibility'], wind_speed=response['wind']['speed'], dt=response['dt']) print("Entry for time {} added successfully".format(
cv2.waitKey(0) elif name is not "": myScraper.scrape_game(search_query, name) except IndexError: font = cv2.FONT_HERSHEY_COMPLEX colour = (0, 0, 0) cv2.putText(frame, 'No game found ', (9, 28), font, 0.55, colour, 2, cv2.LINE_AA) if __name__ == '__main__': # initiate web scraping object myScraper = Scraper() # avatar database access object myDb = DataBase('avatar.db') # collector database object collectordb = CollectorDB('collector.db') # image correction object imageCorrection = ImageCorrection() # edge detection object edge_detection = EdgeDetection() # image warping object image_warper = ImageWarper() # image hashing object image_hasher = ImageHasher() # root for Tk object root = Tk() topframe = Frame(root) topLabel = Label(root, text="What would you like to do?") topLabel.grid(row=0, column=0)
def bms_showtime_count(self, thread_name, starts, stops): connection = DataBase().connection() cursor = connection.cursor() BmsShowTimes().getBmsShowTimes(starts, stops)
''' Created on 16-Jun-2017 @author: H-7 ''' from bs4 import BeautifulSoup import re import requests import string import json import mysql.connector from Database import DataBase from mysql.connector import MySQLConnection, Error connection = DataBase().connection() cursor = connection.cursor() query = 'SELECT distinct(city) FROM moviesfyi_stage.bk_theaters where theater_url is null;' cursor.execute(query) results = cursor.fetchall() city = "" k = 1 for j in results: if (" " in j[0]): city = j[0].replace(" ", "-") print city print "++++++++++++" if ("(" in city): city = city.replace("(", "") city = city.replace(")", "") else: city = j[0].replace(" ", "-") else:
def getmovie(self, starts, stops): sql = "SELECT id,city,theater_url,state from moviesfyi_stage.bk_theaters_final where theater_url is not null and id between " + str( starts) + " and " + str(stops) try: connection = DataBase().connection() cursor = connection.cursor() cursor.execute(sql) results = cursor.fetchall() for i in results: city = i[1] # city="bengaluru" theater_url = i[2] state = i[3] url = "https://in.bookmyshow.com/" + theater_url # print url r = requests.get(url) data = r.text soup = BeautifulSoup(data, "lxml") for j in soup.find_all("ul", id="showEvents"): try: movies_ins = "" for k in j.find_all("div", class_="listing-info"): # print k # print "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" lang = k.find("div", class_="eventInfo") url = k.find("a") languag = lang.text mov_url = url["href"] movie_url = mov_url ''' BMS Movies Page ''' qwe = requests.get("https://in.bookmyshow.com" + movie_url) asdfg = qwe.text moviecook = BeautifulSoup(asdfg, "lxml") relda = moviecook.find( "span", class_="__release-date").text relda = relda.replace(",", "") relda = relda.replace(" ", "-") asd = relda.split("-") releasedate = datetime.datetime.strptime( relda, '%d-%b-%Y').strftime('%Y-%m-%d') gene = "" for bgen in moviecook.find_all("span", itemprop="genre"): gene = gene + bgen.text + "|" genere = "|" + gene censo = moviecook.find("span", class_="__censor") senso = censo.find("use") # print senso # print "----------------------------" sensor = senso["xlink:href"] movie_censor = sensor[sensor.rindex("-") + 1:] movie_censor = movie_censor.upper() mv_pstr = moviecook.find("div", class_="poster wow") mov_posr = mv_pstr.find("meta") movie_poster = mov_posr["content"] movie_banner = movie_poster.replace( "poster", "banner") # print movie_banner movie_tari = moviecook.find( "div", class_="banner-main synopsis-banner") movie_trailer_code = movie_tari[ "data-trailer-code"] # print movie_trailer_code movie_trailer = "https://www.youtube.com/watch?v=" + movie_trailer_code movie_description = moviecook.find( "meta", itemprop="description") movie_description = movie_description["content"] movie_description = specialCharacterConverter.decode_unicode_references( movie_description) movie_description = movie_description.replace( "'", "") # print movie_description ''' Back to Theatres ''' dimes = "" movie_code = movie_url[movie_url.rindex("/") + 1:] mov_url = mov_url.replace("/movies/", "") mov_url = mov_url.replace("/" + movie_code, "") mov = url.text.strip() deumlan = "" movie_dim = "2D" rm_lan = "- " + languag if rm_lan in mov: movi = mov.replace(rm_lan, "") if "(" in movi: deumlan = movi[movi.rindex("(") + 1:] dimes = deumlan if " " in dimes: movie_dim = dimes.split(" ") movie_dim = movie_dim[0] else: movie_dim = "2D" movi = movi.split("(") movi = movi[0] deumlan = deumlan.replace(")", "").strip() deumlan = deumlan.replace(" ", "-") deumlan = deumlan.lower() if deumlan in mov_url: mov_url = mov_url.replace( "-" + deumlan, "") else: mov_url = mov_url else: movi = movi # print languag # print mov_url # print movi # print movie_code # print releasedate # print movie_dim movie_flag = city + movie_code movies_ins = movies_ins + "('" + state + "','" + city + "','" + movi + "','" + genere + "','" + movie_censor + "','" + movie_banner + "', '', '" + movie_poster + "', '" + languag + "', '" + movie_dim + "', '" + releasedate + "', '" + movie_description + "', '" + movie_trailer + "', '', '','" + movie_code + "', '" + mov_url + "','" + movie_flag + "')," # print "--------------------" movies_ins = movies_ins[:-1] # print movies_ins insmovieinfo = "INSERT ignore INTO moviesfyi_stage.bk_movies (state, city, title, genre, censor, desktop_banner, mobile_banner, poster, language, dimension, release_date, description, trailer_url, rating, votes, movie_code, movie_url, book_groupcode) values " + movies_ins # print insmovieinfo try: cursor.execute(insmovieinfo) connection.commit() except: print sys.exc_info() # print testurl print insmovieinfo except: "" except: ""
def get(self): action = request.args.get('action', default="", type=str) farmId = str(request.args.get('farmId', default=0, type=int)) if farmId is not 0: if DataBase().sqlSelectJson(farmId=farmId)['farmId']: gold = DataBase().sqlSelectJson(farmId=farmId)['gold'] now = datetime.now() if action == "Sowing": costOfSowing = DataBase().sqlSelectJson( farmId=farmId)['costOfSowing'] if gold >= costOfSowing: StrTimeOFHarvest = now + timedelta( seconds=DataBase().sqlSelectJson( farmId="1")['growTime']) StrTimeOFHarvest.strftime("%d/%m/%Y %H:%M:%S") DataBase().update( """UPDATE Farms SET gold=?,timeOfsowing=?, timeOfharvest=?,isHarvested=? WHERE farmId= """ + farmId + """;""", (gold - DataBase().sqlSelectJson( farmId=farmId)['costOfSowing'], now.strftime("%d/%m/%Y %H:%M:%S"), StrTimeOFHarvest.strftime("%d/%m/%Y %H:%M:%S"), 0)) dumpsJson = DataBase().sqlSelectJson(farmId=farmId) RemainingTime = datetime.strptime( dumpsJson['timeOfHarvest'], "%d/%m/%Y %H:%M:%S") - now dumpsJson["RemainingTime"] = strfdelta(RemainingTime) return json.dumps(dumpsJson) else: dumpsJson = DataBase().sqlSelectJson(farmId=farmId) RemainingTime = datetime.strptime( dumpsJson['timeOfHarvest'], "%d/%m/%Y %H:%M:%S") - now dumpsJson["RemainingTime"] = strfdelta(RemainingTime) return json.dumps(dumpsJson) elif action == "harvest": if now > datetime.strptime( DataBase().sqlSelectJson( farmId="1")['timeOfSowing'], "%d/%m/%Y %H:%M:%S") + timedelta(seconds=DataBase( ).sqlSelectJson(farmId="1")['growTime']): DataBase().update( """UPDATE Farms SET gold=?, isHarvested=? WHERE farmId= """ + farmId + """;""", (gold + DataBase().sqlSelectJson( farmId=farmId)['productionLimit'], 1)) dumpsJson = DataBase().sqlSelectJson(farmId=farmId) RemainingTime = datetime.strptime( dumpsJson['timeOfHarvest'], "%d/%m/%Y %H:%M:%S") - now dumpsJson["RemainingTime"] = strfdelta(RemainingTime) return json.dumps(dumpsJson) else: dumpsJson = DataBase().sqlSelectJson(farmId=farmId) RemainingTime = datetime.strptime( dumpsJson['timeOfHarvest'], "%d/%m/%Y %H:%M:%S") - now dumpsJson["RemainingTime"] = strfdelta(RemainingTime) return json.dumps(dumpsJson) elif action == 'UpdateFarm': updateCost = DataBase().sqlSelectJson( farmId=farmId)['updateCost'] if gold <= updateCost: dumpsJson = DataBase().sqlSelectJson(farmId=farmId) RemainingTime = datetime.strptime( dumpsJson['timeOfHarvest'], "%d/%m/%Y %H:%M:%S") - now dumpsJson["RemainingTime"] = strfdelta(RemainingTime) return json.dumps(dumpsJson) else: DataBase().update( """UPDATE Farms SET gold=?,productionLimit=?, costOfsowing=? ,updateCost=?, growTime=?, isHarvested=? WHERE farmId= """ + farmId + """;""", (gold - updateCost, DataBase().sqlSelectJson( farmId=farmId)['productionLimit'] + 20, DataBase().sqlSelectJson( farmId=farmId)['costOfSowing'] + 15, DataBase().sqlSelectJson( farmId=farmId)['updateCost'] + 2, DataBase().sqlSelectJson( farmId=farmId)['growTime'] + 10, 0)) dumpsJson = DataBase().sqlSelectJson(farmId=farmId) RemainingTime = datetime.strptime( dumpsJson['timeOfHarvest'], "%d/%m/%Y %H:%M:%S") - now dumpsJson["RemainingTime"] = strfdelta(RemainingTime) return json.dumps(dumpsJson) else: dumpsJson = DataBase().sqlSelectJson(farmId=farmId) RemainingTime = datetime.strptime( dumpsJson['timeOfHarvest'], "%d/%m/%Y %H:%M:%S") - now dumpsJson["RemainingTime"] = strfdelta(RemainingTime) return json.dumps(dumpsJson) else: return "InvalidFarmID" else: return " FarmID = 0"
import data from Database import DataBase from vk_server import vk_server import vk_api import pymysql db = DataBase(data.database['host'], data.database['username'], data.database['password'], data.database['database'], data.database['port']) while True: try: vk = vk_server(data.vk_token, data.bot_id, db) vk.start() except vk_api.exceptions.ApiError: print("Неверно указаны данные для работы Бота") break except pymysql.err.OperationalError: print("Неверно указаны данные для работы с БД") break except: continue
''' Created on 20-Jun-2017 @author: M Manoj @contact: [email protected] ''' from Database import DataBase connection = DataBase().connection() cursor = connection.cursor() cursor.execute(DataBase().bms_estimator) results = cursor.fetchall() for j in results: try: price = int(j[12]) totalseats = int(j[13]) availableseats = int(j[14]) estimated_collection = "" est_occupancy = "" filledseats = (totalseats - availableseats) query = "" if (availableseats <= filledseats): est_occupancy = str(100) estimated_collection = totalseats * price print estimated_collection estimated_collection = str(estimated_collection) est_occupancy = str(est_occupancy) else: bmsoccupancy = (filledseats * 100) / totalseats print j[0] offocc = (availableseats - filledseats) * 100 / totalseats #print offocc