Beispiel #1
0
 def _prepare(self):
     
     users = self.support_vectors.get('users').execute()
     filtered_username_list = [u for u in users if 'sql' in u.lower() or 'sql' in users[u].descr.lower() or (users[u].uid == 0) or (users[u].uid > 999) or (('false' not in users[u].shell) and ('/home/' in users[u].home))  ]
     
     self.args['username_list'] = filtered_username_list
     Sql._prepare(self)
Beispiel #2
0
	def restoreBackup(self, backup):
		tempResources = 'resources-tmp'
		if 'No such file' not in commands.getoutput('ls ' + os.path.join(os.getcwd(), backup)):
			sqlShell = Sql(self.run)
			if sqlShell.checkConnection():
				self.upload(os.path.join(os.getcwd(), backup), os.path.join(self.remoteDir, backup))

				result = self.run('tar -xf ' + backup)
				if 'Error' in result:
					print result
					sys.exit(-1)
					
				sqlShell.restoreDbs('sql.tar')
				self.run('rm -rf sql.tar')
				
				self.run('mkdir -p resources-tmp')
				result = self.run('tar -xf resources.tar -C resources-tmp')
				if 'Error' in result:
					print result
					sys.exit(-1)
				
				
				self.run('mv resources resources-old; mv resources-tmp/resources resources')
				self.run('rm -rf resources-old resources-tmp resources.tar')
				self.run('mkdir -p resources/catroid; for file in resources/projects/*; do filename=`basename "$file"`; unzip -d "resources/catroid/${filename%.*}" "$file"; done')
				self.run('chmod -R 0777 resources')

				print 'restored backup: ' + backup
		else:
			print 'FATAL ERROR: No such file: ' + backup
Beispiel #3
0
 def _prepare_probe(self):
     
     users = self.support_vectors.get('users').execute()
     filtered_username_list = [u for u in users if 'sql' in u.lower() or 'sql' in users[u].descr.lower() or (users[u].uid == 0) or (users[u].uid > 999) or (('false' not in users[u].shell) and ('/home/' in users[u].home))  ]
     
     self.args['username_list'] = filtered_username_list
     Sql._prepare_probe(self)
Beispiel #4
0
	def run(self, type='development', files='all', release=today):
		self.checkSetup()
		
		if not os.path.isdir(os.path.join(self.buildDir, release)) and not os.path.isdir(os.path.join(self.buildDir, self.today)):
			Release().create(files)
		else:
			print('Do you want to update your release build [Y/n]?')
			if sys.stdin.readline() != 'n\n':
				Release().create(files)
		
		if type == 'catroidtest':
			for line in fileinput.FileInput(os.path.join(self.buildDir, release, 'config.php'), inplace=1):
				if "define('UPDATE_AUTH_TOKEN" in line:
					line = "define('UPDATE_AUTH_TOKEN',true);\n" 
				sys.stdout.write(line)
		
		if type == 'public':
			for line in fileinput.FileInput(os.path.join(self.buildDir, release, 'config.php'), inplace=1):
				if "define('DEVELOPMENT_MODE" in line:
					line = "define('DEVELOPMENT_MODE',false);\n" 
				sys.stdout.write(line)
		
		print type
		if type == 'development':
		  sqlShell = Sql(self.remoteCommand,'webtest')
		else:
			sqlShell = Sql(self.remoteCommand,'catroweb')
		  
		if sqlShell.checkConnection():
			self.upload(os.path.join(self.buildDir, release), self.remoteDir)
			self.moveFilesIntoPlace(os.path.join(self.buildDir, release), release)
			sqlShell.initDbs()
		else:
			print('ERROR: deployment failed!')
			self.sftp.put(os.path.join(self.basePath, 'passwords.php'), os.path.join(self.remoteDir, 'passwords.php'))
 def __init__(self, dbName, dbPassword, tableName, coinbasePassword,
              contractAddress, contractAbi):
     super(pushMes, self).__init__()
     self.sql = Sql("localhost", 3306, 'root', dbPassword, dbName)
     self.tableNeedRead = tableName
     self.databaseName = dbName
     self.geth = Ethereum(coinbasePassword, contractAddress, contractAbi)
    def log_temps(self):
        """
        Method is used to log the temperatures to the database, no other actions happen here.
        """
        try:
            self.log.debug("Attempting to get DB connection")
            self.sql = Sql()
        except Exception as e:
            self.log.error(e, exc_info=True)
            return

        self.log.debug("DB connection acquired")
        # Get all sensors from db
        sensors_list = self.sql.get_sensors()
        for sensor in sensors_list:
            # Get sensor object
            s = TemperatureSensor(*sensor)
            # Read the sensor
            humidity, temperature = ada.read_retry(s.sensor_type, s.gpio)
            s.humidity = humidity
            s.temperature = (temperature * 1.8 + 32)
            if s.humidity:
                s.device_online = True
            # Commit the data
            self.sql.set_reading(s)
        # Close connection to the database
        self.sql.close()
Beispiel #7
0
def getData(city_code=None, post_code=None):

    print("###### begin crawl....")

    for index in range(1, 11):
        url = "https://www.zhipin.com/c{}-p{}/h_{}/?page={}&ka=page-next".format(
            city_code, post_code, city_code, index)
        htmldata = getHtmlData(url)
        jobs = getJobList(htmldata)
        print("###### crawl url ===== {}".format(url))
        if len(jobs) != 0:

            for job in jobs:
                isExistJob = Sql.select_jobs_jobid(job["job_id"])
                if isExistJob == True:
                    Sql.update_jobs(job["job_id"], job["job_name"],
                                    job["job_company"], job["experience"],
                                    job["job_pay"], job["min_pay"],
                                    job["max_pay"])
                else:
                    Sql.insert_jobs(job["job_id"], job["job_name"],
                                    job["job_company"], job["experience"],
                                    job["job_pay"], job["min_pay"],
                                    job["max_pay"])

    print("###### finish crawl....")
    def check_relays(self):
        try:
            self.log.debug("Attempting to get DB connection for relays")
            self.sql = Sql()
        except Exception as e:
            self.log.error(e, exc_info=True)
            return
        self.log.debug("DB connection acquired")
        try:
            daytime = DaytimeCycle(*self.sql.get_daytime())
        except Exception as e:
            self.log.error(e, exc_info=True)
            return

        # We have to check for temps and then for day and night
        try:
            relays = self.sql.get_relays()
        except Exception as e:
            self.log.error(e, exc_info=True)

        for relay in relays:
            r = Relay(*relay)
            if r.control == 'light':
                self.log.debug(f"Testing {r}")
                r = self.set_state(r, daytime)
                self.set_gpio(r)
Beispiel #9
0
def settings_apply():
    """
        機運設定適用.
    """

    # POSTデータ取得.
    data = request.form.to_dict(flat=False)
    logger.debug(data['kiun_names'])

    # 設定更新.
    api = twitter_get_api()
    user = api.me()

    sql = Sql()
    sql.connect()
    param = sql.get_user_parameter(user.id)

    for i, name in enumerate(data['kiun_names']):
        # 機運名が変更された項目は機運ゲージを0にする.
        if name != param['kiun_names'][i]:
            param['kiun_values'][i] = 0

    sql.update_user_parameter(user.id, data['kiun_names'],
                              param['kiun_values'])
    sql.close()

    # rootページへ戻る.
    return redirect(configuration.ROOT_URL)
Beispiel #10
0
def get_good_dic() -> dict:
    """Возвращает словарь с информацией из первой (хорошей) базы данных"""
    dic_good = {}
    # получаем информацию из нормальной базы данных
    base_good = Sql("Wargaming.db")
    tables_names = base_good.get_all_tables()
    tables_names = [list(i) for i in tables_names]
    for i in tables_names:
        inf = base_good.exec_custom_command(f'SELECT * FROM {i[0]}')
        inf = [list(i) for i in inf]
        dic_good[i[0]] = inf
    return dic_good
Beispiel #11
0
    def _probe(self):

        result = {}

        for user in self.args['username_list']:
            self.args['username'] = user
            try:
                Sql._probe(self)
            except ProbeSucceed:
                result[user] = self._result[1]
                self._result = []

        self._result = result
Beispiel #12
0
    def _probe(self):

        result = {}

        for user in self.args['username_list']:
            self.args['username'] = user
            try:
                Sql._probe(self)
            except ProbeSucceed:
                result[user] = self._result[1]
                self._result = []

        self._result = result
Beispiel #13
0
    def selectuser(user, password):
        if user == None and password == None:
            return 'login'
        if user != '' and password != '':
            s = Sql()
            re = s.select(userName=user)
            for r in re:
                u = r[0]
                p = r[1]
                t = r[2]

            if user == u and password == p:
                return 1
        else:
            return 0
Beispiel #14
0
    def history(user_number, count, last_timestamp):
        conn = None
        try:
            conn, cur = Sql.get_connection()
            sql_query = "select * from user_history where timestamp < {0} limit count"
            cur.execute(sql_query)
            data = cur.fetchall()

            output = {}
            ind = 0
            for r in data:
                _user_number = str(r[0])
                _booking_id = str(r[1])
                timestamp = r[2]
                output[ind] = {}
                output[ind]["userNumber"] = _user_number
                output[ind]["bookingId"] = _booking_id
                output[ind]["timestamp"] = timestamp
                ind = ind + 1

            conn.close()
            result = Response.make_response(200,
                                            "",
                                            "History fetched",
                                            history=output)
            return result
        except Exception as e:
            if conn is not None:
                conn.close()
            logging.error("Error in showing history for user number " +
                          str(user_number) + ": " + str(e))
            return Response.default_error
Beispiel #15
0
    def end_trip(user_number, booking_id):
        conn = None
        try:
            conn, cur = Sql.get_connection()
            logging.debug("  " + str(user_number) +
                          ":  Connection and cursor received")
            status = Firebase.reset_user(user_number)
            logging.debug("  " + str(user_number) + ":  User reset done")
            if status == 0:
                raise ValueError("Error in ending trip")

            sql_query = "update user_booking set activity = concat(activity, '|', 'user_end_trip'), status = {0} where booking_id = '{1}' and status != {2}"
            cur.execute(
                sql_query.format(C.USER_END_TRIP, booking_id, C.USER_END_TRIP))
            conn.commit()

            conn.close()
            result = Response.make_response(200, "Ended", "Trip ended")
            return result
        except Exception as e:
            if conn is not None:
                conn.close()
            logging.error("  " + str(user_number) +
                          ":  Error in end trip request: " + str(e))
            return Response.default_error
Beispiel #16
0
    def get_all(number):
        conn = None
        try:
            conn, cur = Sql.get_connection()
            logging.debug("Connection and cursor received")

            sql_query = "select name, number, vehicle from drivers where number  = '{0}'"
            cur.execute(sql_query.format(number))
            data = cur.fetchall()
            result = Response.make_response(200,
                                            "Vehicle number updated",
                                            "Vehicle number updated",
                                            name=data[0],
                                            number=data[1],
                                            vehicle=data[2])
            conn.close()
            logging.debug("Connection closed")
            return result
        except Exception as e:
            if conn is not None:
                conn.close()
            logging.error("Error in getting all details: " + str(e))
            error = Response.make_response(500, "System failure",
                                           "Oops something went wrong !")
            return error
Beispiel #17
0
    def start_trip(user_number, booking_id):
        conn    = None
        try:
            conn, cur                       = Sql.get_connection()
            
            status                          = Firebase.start_trip(user_number)
            if status == 0:
                raise ValueError("Error in starting trip")
            
            sql_query                       = "update user_booking set activity = concat(activity, '|', 'user_in_ride'), status = {0} where booking_id = '{1}'"
            cur.execute(sql_query.format(C.USER_IN_RIDE, booking_id))
            conn.commit()

            sql_query = "update distance set status = 0 where booking_id = '{0}'"
            cur.execute(sql_query.format(booking_id))
            conn.commit()

            conn.close()
            result  = Response.make_response(200, "Started", "Trip started")
            return result
        except Exception as e:
            if conn is not None:
                conn.close()
            logging.error("Error in start trip request: " + str(e))
            return Response.default_error
Beispiel #18
0
    def check_user_repetition(number):
        conn = None
        try:
            conn, cur = Sql.get_connection()
            logging.debug("  " + str(number) +
                          ":  Connection and cursor received")

            # check from db
            sql_query = "select count(number) from users where number = '{0}'"
            cur.execute(sql_query.format(number))
            data = cur.fetchone()
            logging.debug("  " + str(number) + ":  Count is: " + str(data[0]))
            if int(data[0]) == 0:
                conn.close()
                result = Response.make_response(200,
                                                "Phone number does not exist",
                                                "Phone number does not exist",
                                                present=0)
                return result
            result = Response.make_response(200,
                                            "Phone number already exists",
                                            "Phone number already exists",
                                            present=1)
            conn.close()
            logging.debug("  " + str(number) + ":  Connection closed")
            return result
        except Exception as e:
            if conn is not None:
                conn.close()
            logging.error("  " + str(number) +
                          ":  Error in checking user repetition: " + str(e))
            error = Response.make_response(500, "System failure",
                                           "Oops something went wrong !")
            return error
Beispiel #19
0
 def create_otp(number):
     conn   = None
     try:
         conn, cur               = Sql.get_connection()
         logging.debug("  " + str(number) + ":  Connection and cursor received")
         response                = requests.get("https://2factor.in/API/V1/" + str(config.api_key_2factor) + "/SMS/+91" + str(number)[-10:]+ "/AUTOGEN")
         response                = dict(response.json())
         if response["Status"] == "Success":
             session_id          = response["Details"]
             logging.debug("  " + str(number) + ":  OTP created successfully with session id: " + str(session_id))
             
             sql_query           = "insert into user_otp (number, session_id) values ('{0}', '{1}') on duplicate key update session_id = '{1}', otp_verified = 0"
             cur.execute(sql_query.format(number, session_id))
             conn.commit()
             logging.debug("  " + str(number) + ":  Connection closed")
             result              = Response.make_response(200, "OTP sent", "Please enter otp")
             conn.close()
             return result
         else:
             logging.warning("  " + str(number) + ":  OTP could not be created")
             error = Response.make_response(500, "System failure", "Oops something went wrong !")
             conn.close()
             return error
     except Exception as e:
         if conn is not None:
             conn.close()
         logging.error("  " + str(number) + ":  Error in create_otp: " + str(e))
         error = Response.make_response(500, "System failure", "Oops something went wrong !")
         return error
Beispiel #20
0
    def create_user(number, name):
        conn = None
        try:
            conn, cur = Sql.get_connection()
            logging.debug("  " + str(number) +
                          ":  Connection and cursor received")

            # insert in db
            sql_query = "insert into users (number, name) values ('{0}', '{1}')"
            cur.execute(sql_query.format(number, name))
            conn.commit()
            logging.debug("  " + str(number) +
                          ":  User successfully inserted in users table")
            result = Response.make_response(201, "Account created",
                                            "Your account has been created")
            conn.close()
            return result
        except Exception as e:
            if conn is not None:
                conn.close()
            logging.error("  " + str(number) + ":  Error in creating user: "******"System failure",
                                           "Oops something went wrong !")
            return error
Beispiel #21
0
def improvise(message):
    print(" >>> " + message.from_user.first_name + " : " + message.text)
    if "📝" in message.text:
        db = Db(sqlite3.connect('booba.db'), Sql())
        generator = Generator('booba', db, Rnd())
        msg = generator.generate(' ') + "\n" + generator.generate(' ')
        bot.send_message(message.chat.id, msg)
Beispiel #22
0
    def cancel_booking(user_number, booking_id):
        conn = None
        try:
            conn, cur = Sql.get_connection()
            logging.debug("  " + str(user_number) +
                          ":  Connection and cursor received")
            status = Firebase.reset_user(user_number)
            if status == 0:
                return Response.default_error

            sql_query = "update user_booking set status = {0}, activity = concat(activity, '|', 'user_cancelled') where booking_id = '{1}' and status != {2}"
            cur.execute(
                sql_query.format(C.USER_CANCELLED, booking_id,
                                 C.USER_CANCELLED))
            conn.commit()

            sql_query = "update distance set status = 0 where booking_id = '{0}'"
            cur.execute(sql_query.format(booking_id))
            conn.commit()

            conn.close()
            logging.debug("Booking cancelled successfully for " +
                          str(user_number))
            result = Response.make_response(200, "Booking cancelled",
                                            "Your booking has been cancelled")
            return result
        except Exception as e:
            if conn is not None:
                conn.close()
            logging.error("  " + str(user_number) +
                          ":  Error in cancelling booking: " + str(e))
            return Response.default_error
Beispiel #23
0
    def find_drivers(user_number, from_lon, from_lat, to_lon, to_lat, seats):
        conn = None
        try:
            conn, cur = Sql.get_connection()
            logging.debug("  " + str(user_number) +
                          ":  Connection and cursor received")
            sql_query = "select count(booking_id) from user_booking where user_number = '{0}' and (status = {1} or status = {2} or status = {3})"
            cur.execute(
                sql_query.format(user_number, C.USER_IN_RIDE, C.USER_BOOKED,
                                 C.USER_REQUESTING))
            current_booking = cur.fetchone()[0]
            # if already there is no booking then proceed
            if current_booking == 0:
                conn.close()
                path_ = "users/" + user_number
                result = Response.make_response(200,
                                                "Success",
                                                "We are searching drivers",
                                                path=path_)
                return result, 1
            else:
                conn.close()
                result = Response.make_response(
                    409, "Booking exists",
                    "You have already one booking going on")
                return result, 0

        except Exception as e:
            if conn is not None:
                conn.close()
            logging.error("  " + str(user_number) +
                          ":  Error in finding drivers: " + str(e))
            return Response.default_error, 0
Beispiel #24
0
def generate(name, count):
    db = Db(sqlite3.connect(name + '.db'), Sql())
    generator = Generator(name, db, Rnd())
    markov_text = []
    for i in range(0, count):
        markov_text.append(generator.generate(WORD_SEPARATOR))

    return markov_text
Beispiel #25
0
def parse(name, depth, file_to_parse):

    db = Db(sqlite3.connect(name + '.db'), Sql())
    db.setup(depth)

    txt = codecs.open(file_to_parse, 'r', 'utf-8').read()
    Parser(name, db, SENTENCE_SEPARATOR, WORD_SEPARATOR).parse(txt)
    print('Database', name, 'created from', file_to_parse)
Beispiel #26
0
def index():
    """
        rootページの表示.
    """
    twitter_login = False
    twitter_id = ''
    user_icon = ''
    kiun_names = None
    kiun_values = None

    # Twitter認証済みチェック.
    if twitter_is_auth():
        # 認証済.
        api = twitter_get_api()
        twitter_login = True
        twitter_user = api.me()
        twitter_id = twitter_user.screen_name
        user_icon = twitter_user.profile_image_url_https

        sql = Sql()
        sql.connect()
        param = sql.get_user_parameter(twitter_user.id)
        sql.close()

        kiun_names = param['kiun_names']
        kiun_values = param['kiun_values']

    # templates/index.html を使ってレンダリング.
    return render_template('index.html',
                           twitter_login=twitter_login,
                           twitter_id=twitter_id,
                           user_icon=user_icon,
                           kiun_names=kiun_names,
                           kiun_values=kiun_values)
Beispiel #27
0
def pontificate(bot, trigger):
    print "Generating sentence..."
    markLen = [int(x) for x in trigger.split() if x.isdigit()]

    db = Db(sqlite3.connect(NAME + '.db'), Sql())
    gen = Generator(NAME, db, Rnd())

    for i in range(0, DEFAULT_LENGTH):
        bot.say(gen.generate(WORD_SEPARATOR))
Beispiel #28
0
def initialize_user_parameter(twitter_user_id):
    """
        ユーザーの設定情報を初期化.
    """
    kiun_names = define.KIUN_DEFAULT_NAME
    kiun_values = [0, 0, 0, 0, 0]

    sql = Sql()
    sql.connect()
    sql.register_user_parameter(twitter_user_id, kiun_names, kiun_values)
    sql.close()
Beispiel #29
0
def get_db(name: str) -> list:
    """Возвращает список, в котором информация из указанной базы данных"""
    mas_all = []
    dic = {}
    base = Sql(name)
    tables_tuple = base.get_all_tables()
    tables_mas = [list(i) for i in tables_tuple]
    for i in tables_mas:
        # убираем из подписей все лишнее
        table_name = i[0]
        podpisi = base.get_table_names(table_name)
        podpisi = [list(x)[1] for x in podpisi]
        inf = base.get_table_inf_by_name(table_name)
        inf = [list(x) for x in inf]
        # собираем информацию и подписи и записываем в inf
        if "ships" not in table_name:
            for j in range(len(inf)):
                for k in range(1, len(inf[j])):
                    inf[j][k] = {podpisi[k]: inf[j][k]}
        mas_all.append(inf)
    ships = mas_all[-1]
    not_ships = mas_all[:-1]
    dic_not_ships = {}
    for i in range(len(not_ships)):
        for j in range(len(not_ships[i])):
            dic_not_ships[not_ships[i][j][0]] = not_ships[i][j][1:]

    for i in range(len(ships)):
        dic[ships[i][0]] = {
            ships[i][1]: dic_not_ships[ships[i][1]],
            ships[i][2]: dic_not_ships[ships[i][2]],
            ships[i][3]: dic_not_ships[ships[i][3]]
        }
    # преобразуем получившийся словарь в двумерный список, который можно поместить в параметризацию
    mas_out = []
    for key, value in dic.items():
        for key1, value1 in value.items():
            for param in value1:
                for key2, value2 in param.items():
                    mas = [key, key1, key2, value2]
                    mas_out.append(mas)
    return mas_out
Beispiel #30
0
 def parsePash(self, n):
     sql = Sql()
     for i in range(15):
         url = 'https://www.3sgif.com/gif/page/%d/' % (i + n * 15 + 1)
         html = self.httpRequest(url)
         add = re.findall(r'https://www.3sgif.com/(\d*).html',
                          html[9500:20000])
         for j in range(int(len(add) / 2)):
             url = 'https://www.3sgif.com/%s.html' % (add[j * 2])
             print(add[j * 2])
             self.parseOne(url, sql)
Beispiel #31
0
	def createBackup(self):
		print 'connecting sql...'
		sqlShell = Sql(self.run)
		if sqlShell.checkConnection():
			print '----start creating sql backup...'
			sqlShell.backupDbs()
			print '----end creating sql backup.'
			print '----start creating resources backup...'
			self.run('rm resources.tar',0)
			self.run('tar -c resources.tar --no-recursion resources/*',0)
			'''for project in sqlShell.getProjectList():
				self.run('tar --append --file=resources.tar resources/projects/%s.*' % project)
				self.run('tar --append --file=resources.tar resources/thumbnails/%s_small*' % project)
				self.run('tar --append --file=resources.tar resources/thumbnails/%s_large*' % project)
			'''
			print 'packing featured'
			self.run('tar --append --file=resources.tar resources/featured/*')
			
			print 'packing projects'
			self.run('tar --append --file=resources.tar resources/projects/*')
			
			print 'packing thumbnails'
			self.run('tar --append --file=resources.tar resources/thumbnails/*')
			
			
			'''for featuredProject in sqlShell.getFeaturedProjectList():
				self.run('tar --append --file=resources.tar resources/featured/%s.*' % featuredProject)
			
			self.run('tar --append --file=resources.tar resources/thumbnails/thumbnail_small.png')
			self.run('tar --append --file=resources.tar resources/thumbnails/thumbnail_large.png')
			'''
			print '----end creating resources backup.'
			print 'adding sql and resources into one package...'
			self.run('tar -zcf catroweb-' + self.today + '.tar.gz sql.tar resources.tar')
			self.run('rm sql.tar resources.tar')
			print 'generated package size:'+ self.run('du -h catroweb-' + self.today + '.tar.gz')
			print 'downloading the package...'
			self.download(os.path.join(self.remoteDir, 'catroweb-' + self.today + '.tar.gz'), os.path.join(os.getcwd(), 'catroweb-' + self.today + '.tar.gz'))
			print 'created backup'
		else:
			print 'failed'
Beispiel #32
0
def kiun_update():
    """
        機運更新.
    """
    print 'kiun_update test!' + request.method

    if request.method == 'POST':

        data = request.form.to_dict(flat=False)
        values = [int(s) for s in data['values']]  # 機運値の文字列リストを数値に変換.

        api = twitter_get_api()
        user = api.me()

        sql = Sql()
        sql.connect()
        param = sql.get_user_parameter(user.id)

        # 機運値をツイート.
        tweet_kiun_gauge(api, param['kiun_names'], values)

        # 機運がMAXになった項目をチェック.
        kiun_max_names = []
        kiun_max_values_index = []
        for i, val in enumerate(values):
            if val == 10:
                kiun_max_names.append(param['kiun_names'][i])
                kiun_max_values_index.append(i)

        # 機運がMAXになった際のツイート.
        if len(kiun_max_names) >= 1:
            tweet_kiun_max(api, kiun_max_names)

        # 0に戻す.
        if len(kiun_max_values_index) >= 1:
            for max_i in kiun_max_values_index:
                values[max_i] = 0

        # 機運値をデータベースに更新.
        sql.update_user_parameter(user.id, param['kiun_names'], values)

        sql.close()

    # templates/kiun_update.html を使ってレンダリング.
    return render_template('kiun_update.html', kiun_max_names=kiun_max_names)
Beispiel #33
0
    def accept(driver_number):
        conn    = None
        try:
            conn, cur                       = Sql.get_connection()
            booking_details                 = Firebase.get_current_request(driver_number)
            if booking_details["bookingId"] == -1:
                raise ValueError('There is no booking for this driver')
            if len(booking_details) == 0:
                raise ValueError('Booking details is empty')
            user_number                     = int(booking_details["user"])
            fare                            = float(booking_details["fare"])
            booking_id                      = booking_details["bookingId"]
            from_lon                        = float(booking_details["from_lon"])
            from_lat                        = float(booking_details["from_lat"])
            to_lon                          = float(booking_details["to_lon"])
            to_lat                          = float(booking_details["to_lat"])
            seats                           = int(booking_details["seats"])
            now_time                        = datetime.timestamp(datetime.now())

            sql_query                       = "select name, vehicle from drivers where number = '{0}'"
            cur.execute(sql_query.format(driver_number))
            d                               = cur.fetchone()
            driver_name                     = str(d[0])
            vehicle                         = str(d[1])
            sql_query                       = "insert into driver_history (booking_id, driver_number, timestamp) values ('{0}', {1}, {2})"
            cur.execute(sql_query.format(booking_id, driver_number, now_time))
            conn.commit()

            sql_query = "insert into distance(booking_id, status, dist, driver, from_lon, from_lat) values('{0}', 1, -1.0, '{1}', {2}, {3})"
            cur.execute(sql_query.format(booking_id, driver_number, from_lon, from_lat))
            conn.commit()

            sql_query                       = "insert into user_history (booking_id, user_number, timestamp) values ('{0}', {1}, {2})"
            cur.execute(sql_query.format(booking_id, user_number, now_time))
            conn.commit()

            status                          = Firebase.confirm_user_booking(user_number, driver_number, driver_name, vehicle)
            
            sql_query                       = "insert into user_booking(booking_id, user_number, status, driver_number, fare, activity, from_lon, from_lat, to_lon, to_lat, seats) values('{0}', '{1}', {2}, '{3}', {4}, '{5}', {6}, {7}, {8}, {9}, {10})"
            cur.execute(sql_query.format(booking_id, user_number, C.USER_BOOKED, driver_number, fare, "user_booked", from_lon, from_lat, to_lon, to_lat, seats))
            conn.commit()
 
            conn.close()
            result = Response.make_response(200, "Driver accepted", "Request accepted successfully", fare = fare, bookingId = booking_id)
            return result
        except Exception as e:
            if conn is not None:
                conn.close()
            logging.error("Error in accepting request: " + str(e))
            return Response.default_error
Beispiel #34
0
	def createBackup(self):
		sqlShell = Sql(self.run)
		if sqlShell.checkConnection():
			sqlShell.backupDbs()
			self.run('tar -c resources.tar --no-recursion resources/*')
			for project in sqlShell.getProjectList():
				self.run('tar --append --file=resources.tar resources/projects/%s.*' % project)
				self.run('tar --append --file=resources.tar resources/thumbnails/%s_small*' % project)
				self.run('tar --append --file=resources.tar resources/thumbnails/%s_large*' % project)

			for featuredProject in sqlShell.getFeaturedProjectList():
				self.run('tar --append --file=resources.tar resources/featured/%s.*' % featuredProject)
			
			self.run('tar --append --file=resources.tar resources/thumbnails/thumbnail_small.png')
			self.run('tar --append --file=resources.tar resources/thumbnails/thumbnail_large.png')
			
			self.run('tar -zcf catroweb-' + self.today + '.tar.gz sql.tar resources.tar')
			self.run('rm sql.tar resources.tar')
			self.download(os.path.join(self.remoteDir, 'catroweb-' + self.today + '.tar.gz'), os.path.join(os.getcwd(), 'catroweb-' + self.today + '.tar.gz'))
			print 'created backup'
Beispiel #35
0
import os,sys,traceback,server,sandbox,json,time,hashlib,lxc,shutil,argparse,datetime,subprocess
from sql import Sql

if os.geteuid() == 0:
	print('Do not ever run me as root!')
	sys.exit(1)
PATH = os.path.dirname(os.path.abspath(__file__))+'/'


with open(PATH+'settings.json') as f:
	config = json.load(f)

sql = Sql()

def hashFolder(path):
	hash = hashlib.sha1()
	for root, dirs, files in os.walk(path):
		for f in files:
			if f[-4:] != '.elf':
				with open(root+'/'+f,'rb') as fp:
					for chunk in iter(lambda: fp.read(4096), b''):
						hash.update(chunk)
	return hash.hexdigest()
def makeUnicode(s):
	try:
		return s.decode('utf-8')
	except:
		return s

LOGLEVELS = ['ERROR','INFO','DEBUG']
Beispiel #36
0
 def _set_vectors(self):
     Sql._set_vectors(self)
     self.support_vectors.add_vector('users', 'audit.etcpasswd',  [])
Beispiel #37
0
		try:
			shell.sftp.mkdir(os.path.join('backup', 'sql'))
			shell.sftp.mkdir(os.path.join('backup', 'sql', 'catroboard'))
			shell.sftp.mkdir(os.path.join('backup', 'sql', 'catroweb'))
			shell.sftp.mkdir(os.path.join('backup', 'sql', 'catrowiki'))
		except:
			pass
				


if __name__ == '__main__':
	parameter = 'empty'
	try:
		if sys.argv[1] == 'website':
			EnvironmentChecker().run()
			sql = Sql()
			sql.initDbs()
			sql.createDocs()
		elif sys.argv[1] == 'tools':
			Selenium().update()
			JSCompiler().update()
			CSSCompiler().update()
		elif sys.argv[1] == 'dev':
			print('Please enter your password to run this script:')
			os.system('sudo sh services/init/environment/local.sh')
		elif sys.argv[1] == 'xmlupdate':
			EnvironmentChecker().updateProjectXMLs()
		elif sys.argv[1] == 'backup':
			SetupBackup().init()
		else:
			parameter = '%s:' % sys.argv[1]