Esempio n. 1
0
def main():
    """you can extract any data from here
    `data`  variable is list type.
    according to anydata.py
    very first element of `data` will be datetime.now()
    ### FOR EXAMPLE
    date_time = data [0]
    temperature = date [1]
    humidity = data [2]
    is_raining = data [3]
    temperature_from_api = data [4]
    hu....._api = data [5]
    wind_kph = data [6]
    """
    while (True):
        try:
            data = data_obj.get()  # getting sensor data

            row_limiter = str(ws.get_last_row() + 1)
            if cloudUpdate:
                ws.post_batch(limiter='A' + row_limiter + ':N' + row_limiter,
                              data_list=data,
                              cloudUpdate=cloudUpdate)
            else:
                WorkSheet.show(['update bypassed', row_limiter, data])
            time.sleep(3)
            if not deadlock:
                break
        except KeyboardInterrupt:
            pylaxz.printf('user stopped', _int=1)
            break
        except Exception as e:
            print(e)
            break
Esempio n. 2
0
def details(*arg):

    users = arg[0]
    metrics = arg[1]

    for user in users:
        user['dataTransferred'] = metrics[user['id']] / \
            (1024**3) if user['id'] in metrics.keys() else None

    if len(arg) == 3:
        for user in users:
            printf(
                f'{user["id"]}, {user["name"]}, {user["dataTransferred"]}GB', _int=1)
        try:
            userID = input("Enter User ID : ")
            userID = int(userID)
            for user in users:
                for k, v in user.items():
                    if k == 'id' and v == str(userID):
                        oneDetails(user['id'], user['name'],
                                   user['password'], user['dataTransferred'],
                                   user['accessUrl'])
        except ValueError:
            print('Only ID.')
        except KeyboardInterrupt:
            print('Exit.')
    else:
        for user in users:
            if user['dataTransferred']:
                if 'dataLimit' in user.keys():
                    printf(
                        f'{user} Found DataLimit:{user["dataLimit"]["bytes"]/(1024**3)}GB', _int=1, _err=1)
                else:
                    printf(user, _int=1)
            else:
                printf('No Usage. {}'.format(user), _int=1, _err=1)
Esempio n. 3
0
    def get(self):
        new_data = list()
        h, t = None, None

        new_data.append(str(datetime.now()))  # 0
        if self.debug:
            pylaxz.printf('sensors: date ... done.')

        h, t = self.get_temp()
        new_data.append(t)  # 1
        new_data.append(h)  # 2

        if self.debug:
            if h and t is not None:
                pylaxz.printf('sensors: HT ... done.', _int=1)
            else:
                pylaxz.printf('sensors: HT sensors error.', _int=1, _err=1)

        new_data.append(0) if self.rain else new_data.append(1)  # 3
        if self.debug:
            pylaxz.printf('sensors: is_raining ... done.', _int=1)

        new_data.append(self.weather['temp_c'])  # 4
        new_data.append(self.weather['humidity'])  # 5
        new_data.append(self.weather['wind_kph'])  # 6

        if self.debug:
            pylaxz.printf('sensors: weather data ... done', _int=1)

        # new_data.append('--Decision--')  # 7

        if self.debug:
            pylaxz.printf('sensors: all done.', _int=1)

        return new_data
Esempio n. 4
0
 def get_temp(self):
     if self.debug:
         pylaxz.printf('get_temp: getting h & t ... ', _int=1)
     return ada.read_retry(ada.DHT11, 4)
Esempio n. 5
0
def oneDetails(userID, userName, userPassword, dataTransferred, ss, dataLimit=None):
    printf(f'ID: {userID}, Name: {userName}, Password: {userPassword}, DataTransferred: {dataTransferred}GB\nAccessURL: {ss}', _int=1)
Esempio n. 6
0
def overview_metrics():
    printf(json.loads(sys.argv[1:][0]), _int=1)
Esempio n. 7
0
def detail_information(*arg):
    metrics_data = json.loads(sys.argv[1:][0])

    # parse single {compact} json string
    access_lists = sys.argv[1:][1][1:-1]

    # manipulate for making string to dictionaries
    access_lists = ['{'+i+'}' for i in access_lists.split('},{')]

    # '[{{},{},{},{}}]' remove '{'....'}'
    access_lists[0] = access_lists[0][1:]
    access_lists[-1] = access_lists[-1][:-1]

    # [{},{},{}]
    access_key_dicts = [json.loads(i) for i in access_lists]

    # printf(access_key_dicts)
    id_or_name = arg[0] if len(arg) > 0 else None
    if id_or_name is not None:
        found_flag = False
        var_id = None
        for i in access_key_dicts:
            for k, v in i.items():
                if k == 'id' or k == 'name':
                    if v == id_or_name:
                        if 'dataLimit' in i:
                            limit = i['dataLimit']['bytes'] / (1024**3)
                            printf("DataLimit Found. : {0:.2f} MB".format(
                                limit), _int=1)
                        else:
                            limit = 0
                        found_flag = True
                        var_id = id_or_name if k == 'id' else i['id']
                        printf(json.dumps(i, indent=4, sort_keys=False), _int=1)
                        try:
                            metric_bytes = metrics_data[var_id]/(1024**3)
                            printf("Usage : {0:.2f} MB".format(
                                metric_bytes), _int=1)
                            if limit != 0:
                                print('Key is DISABLED' if metric_bytes >
                                      limit else 'Warning')
                        except KeyError:
                            printf(f'This ID {var_id} has no usage.', _int=1)
        if not found_flag:
            printf(f'ID : {id_or_name} is Deleted or Not Found !', _int=1)
    else:
        for i in access_key_dicts:
            printf(json.dumps(i, indent=4, sort_keys=False), _int=1)
Esempio n. 8
0
                    if k == 'id' and v == str(userID):
                        oneDetails(user['id'], user['name'],
                                   user['password'], user['dataTransferred'],
                                   user['accessUrl'])
        except ValueError:
            print('Only ID.')
        except KeyboardInterrupt:
            print('Exit.')
    else:
        for user in users:
            if user['dataTransferred']:
                if 'dataLimit' in user.keys():
                    printf(
                        f'{user} Found DataLimit:{user["dataLimit"]["bytes"]/(1024**3)}GB', _int=1, _err=1)
                else:
                    printf(user, _int=1)
            else:
                printf('No Usage. {}'.format(user), _int=1, _err=1)


if __name__ == "__main__":
    if len(sys.argv) == 2:
        overview_metrics()
    elif len(sys.argv) == 3:
        detail_information()
    elif len(sys.argv) == 4:
        detail_information(sys.argv[3])
    else:
        printf('Error few many args : {}'.format(
            len(sys.argv)), _err=True, _int=1)
Esempio n. 9
0
 def post_batch(self, limiter, data_list, cloudUpdate=True):
     if self.debug: pylaxz.printf(limiter, _int=1)
     if self.debug: pylaxz.printf(data_list, _int=1)
     if cloudUpdate: self.worksheet.update(limiter, [data_list])
     if self.debug: pylaxz.printf('data is processed.', _int=1)
Esempio n. 10
0
 def show(data):
     for i in data:
         pylaxz.printf(i, _int=1)