Example #1
0
def _tv_remote_action(arg):
    if arg in _remote_key_codes:
        key_code = _remote_key_codes[arg]

        with samsungctl.Remote(config.SAMSUNG) as remote:
            remote.control(key_code)
    else:
        log.e(f"TV: parameter does not exist: {arg}")
Example #2
0
def add_to_db(json_line):
    '''add entry in json form to database, add fitting _id'''
    if 'COMPLETED' in json_line:
        try:
            entry = json.loads(json_line)
        except ValueError:
            with open(tempfile.mktemp(), 'w') as f:
                f.write(json_line)
                logging.e("invalid json line: %s, see %s", line[:80], f.name)
        if results._db().runs.count(
            {"stop_time": parser.parse(entry['stop_time']['$date'])}):
            logging.warn("seems to already exist: %s", line[:40])
            return
        entry['_id'] = results._next_id()
        imp = subprocess.Popen(["mongoimport", "-c", "runs", "-d", "sacred"],
                               stdin=subprocess.PIPE)
        imp.communicate(input=json.dumps(entry))
    else:
        logging.info("skipped line starting with %s", line[:40])
Example #3
0
def login(request # type: Request
                ):

    if request.method == 'GET':
        cursor = connection.cursor();
        with open("jayson.json") as json_file:
            json_data = json.load(json_file)
            datae = json_data["data"]
            e(datae)
            numb = 1
            for datie in datae:
                try:
                    cursor.execute("""INSERT INTO product
                                    (
                                    `model_num`,
                                    `name`,
                                    `description`,
                                    `price`,
                                    `status`
                                    ) 
                                    VALUES (%s,%s,%s,%s,%s)""",
                                   [datie['Model'],
                                    datie['Model'],
                                    'CPU',
                                    str(random.randint(10000,50000)),
                                    1
                                    ])
                    cursor.execute(""" INSERT INTO `pc_maker`.`cpu`
                                            (`id`,
                                            `base_clock`,
                                            `boost_clock`,
                                            `cores`,
                                            `threads`,
                                            `L1_cache`,
                                            `L2_cache`,
                                            `L3_cache`,
                                            `unlocked`,
                                            `socket`,
                                            `passmark`)
                                            VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
                                   [
                                       cursor.lastrowid,
                                       datie['Max Boost'],
                                       datie['Base Clock'],
                                       datie['# of CPU Cores'],
                                       datie['# of Threads'],
                                       datie['Total L1 Cache'],
                                       datie['Total L2 Cache'],
                                       datie['Total L3 Cache'],
                                       'True',
                                       1,
                                       random.randint(40000,100000)



                                   ])
                except Exception as ioj:
                    print('oij')






        return Response({
            "something": "somethingwe",
            "data": datae
        })
    elif request.method == 'POST':
        data = request.data
        try:
            email = data['email']
            password = data['password']
            e(password)
            result = run_basic_query(f'select * from user where username like \"{email}\"')
            e(result)
            dickt = dict(zip(result['desc'], result['result'][0]))
            e(password)
            real_password = dickt['u_password']
            if password == real_password:
                e('itsthesame')
                dickt['status'] = "success";
                user_id = dickt['id']
                e(user_id)
                cursor = connection.cursor()
                cursor.execute('select * from admin_table where id = %s',(str(user_id)))
                if(cursor.rowcount == 1):
                    dickt['admin']  = True
                return Response(
                    dickt

                )
            else:
                Response({
                    "status": "Unsuccessful"
                })
        except Exception as err:
            e(err)
            return Response({

                "error": "Bad request "
            })

        return Response(
            {
                "status": "Faliure",
                "reason": "Wrong password has been entered"
            }
        )
Example #4
0
import SoccerUtil as su
import logging
from logging import debug as d,info as i,warning as w,error as e,critical as c


#
logging.basicConfig(level=logging.DEBUG)
print(su.LEAGUE)
# debug('a')
# info('b')
# error('c')
# warning('d')
# critical('e')
# critical(su.LEAGUE)

d('a')
i('b')
e('c')
w('d')
c('e')
c(su.LEAGUE)
#


#
# f = open("const.json",encoding="utf-8")
#
# setting = json.load(f)
#
# print(setting)
#
Example #5
0
def register(request  # type: Request
             ):
    cursor = connection.cursor()
    if request.method == 'POST':
        data = request.data  # type: dict
        quer_str = ' '
        try:
            action = data['action']
            email = data['email']

            def verify_existance():
                q_result = be(
                    f'select count(*) from user where email = \"{email}\" ')
                e(q_result['result'][0][0])
                num = q_result['result'][0][0]
                return num == 0

            if action == 'register':
                password = data['password']
                first_name = data['first_name']
                middle_name = data['middle_name']
                last_name = data['last_name']
                if verify_existance():
                    try:
                        cursor.execute(
                            """insert into user (email,u_password,first_name,middle_name,last_name)
                                      values ( %s, %s, %s, %s, %s )""",
                            (email, password, first_name, middle_name,
                             last_name))
                        q_result = cursor.execute(
                            f'select * from user where id =  (select max(id) from user)'
                        )

                        return Response({
                            "result":
                            cursor.lastrowidd,
                            "status":
                            "Successful",
                            "with":
                            dict(
                                zip([desc[0] for desc in cursor.description],
                                    [item for item in list(cursor)[0]]))
                        })
                    except Exception as excepp:
                        return Response({
                            "oisdj": "osdhjios",
                            "error": str(excepp)
                        })
                else:
                    return Response({
                        "error":
                        "User already exists, use forgot password or update credentials"
                    })

            elif action == 'update':
                if not verify_existance():

                    try:
                        quer_str = ' '
                        datacpy = dict(data)
                        del datacpy['email']
                        del datacpy['action']
                        # del datacpy['image']
                        for desc in datacpy.keys():
                            print(desc)
                            quer_str += str(desc) + ' = \"' + str(
                                datacpy[desc][0]) + '\"' + ', '
                        quer_str = quer_str[:-2] + ' '
                        print(quer_str)
                        q_res = iq(
                            f'update \"user\" set {quer_str} where \"username\" like \"{email}\"'
                        )
                        return Response({
                            "result": "Updated successfully",
                            "row": q_res.lastrowid
                        })
                    except Exception as excep:
                        e(excep)

        except Exception as excep:
            e(excep)
            return Response({"error": "Error in the fields given"})
Example #6
0
 def verify_existance():
     q_result = be(
         f'select count(*) from user where email = \"{email}\" ')
     e(q_result['result'][0][0])
     num = q_result['result'][0][0]
     return num == 0