示例#1
0
 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"
示例#2
0
 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("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"
示例#4
0
 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
示例#5
0
 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 bms_showtime_count(self, thread_name, starts, stops):
     connection = DataBase().connection()
     cursor = connection.cursor()
     BmsShowTimes().getBmsShowTimes(starts, stops)
示例#7
0
'''
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:
示例#8
0
    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:
            ""