Beispiel #1
0
 def _load_config(self) -> None:
     ''' load config '''
     h = myutil.get_home()
     p = h + '/Private/reurl.json'
     conf = myutil.read_jsonfile(p)
     self.server = conf['server']
     self.apikey = conf['apikey']
 def load_setting(self):
     ''' load setting '''
     if not myutil.isfile(self.sett_json):
         print(f'[FAIL] setting file not found: {self.sett_json}')
     sett = myutil.read_jsonfile(self.sett_json)
     self.data_file_name = sett.get('data_file_name')
     self.resp_json = sett.get('resp_json')
Beispiel #3
0
 def load_setting(self, fn):
     data = myutil.read_jsonfile(fn, debug=True)
     try:
         tmp = data['auto_save']
         self.auto_save = tmp
     except:
         pass
     print('setting loaded, auto_save: {}'.format(self.auto_save))
Beispiel #4
0
def main():
    ''' main '''
    js = read_jsonfile('seq.json')
    print('len of keys: ', len(js))
    count = 0

    for k in js:
        count += len(js[k])

    print('total values: ', count)
    output_as_list(js)
Beispiel #5
0
def get_randomorg_apikey():
    ''' get apikey of random.org from json file '''
    home = os.environ.get('HOME')
    keypath = home + '/' + 'Private/random-org.json'
    if not myutil.isfile(keypath):
        print('[FAIL] key file not exist: {}'.format(keypath))
        return ""
    data = myutil.read_jsonfile(keypath)
    apiKey = data.get('apiKey')
    if apiKey is None:
        print('[WARN] apiKey is None')
        return ""
    return apiKey
 def check_and_store(self):
     ''' if no data here, read json and store it '''
     try:
         res = self.test_one_query('284', show=False)
         if res is None:
             print('[INFO] no data stored? read and store it')
             self.data = read_jsonfile(self.fn)
             self.rj.jsonset(self.objname, Path.rootPath(), self.data)
             print(f'[INFO] read {self.fn} and store as {self.objname}')
     except redis.exceptions.ConnectionError as e:
         print('[ERROR] cannot connect to redis server:\n', e)
         print('\nNeed start the service of redis/rejson first.')
         sys.exit(1)
Beispiel #7
0
def get_randomorg_apikey():
    ''' get apikey of random.org from json file '''
    home = os.environ.get('HOME')
    keypath = home + '/' + 'Private/random-org.json'
    if not myutil.isfile(keypath):
        print(f'[FAIL] key file not exist: {keypath}')
        return ""
    data = myutil.read_jsonfile(keypath)
    apiKey = data.get('apiKey')
    if apiKey is None:
        print('[WARN] apiKey is None')
        return ""
    return apiKey
Beispiel #8
0
 def _connect(self):
     ''' connect to redis '''
     h = get_home()
     fn = h + '/Private/redis.json'
     data = read_jsonfile(fn)
     print(f"host: {data['host']}, port: {data['port']}")
     try:
         self.redis = redis.Redis(host=data['host'], port=data['port'], \
             decode_responses=True, charset='utf-8', password=None)
         self.redis.ping()
     except redis.exceptions.ConnectionError as e:
         print('Need redis server running\n', e)
         sys.exit(1)
 def _load_config(self):
     ''' load miranda.json from ${HOME}/Private '''
     h = get_home()
     conf = h + '/Private/miranda.json'
     data = None
     if os.path.exists(conf):
         data = read_jsonfile(conf)
     else:
         print(f'cannot load config file from {conf}')
         sys.exit(1)
     if data:
         self.path = data["path"]
         print(f'[INFO] path of miranda: {self.path}')
Beispiel #10
0
    def read_setting(self):
        ''' read setting '''
        if self.debug:
            print('read_setting()')

        home = os.getenv('HOME')
        self.jsonpath = home + '/Private/driving_data.json'
        if not myutil.isfile(self.jsonpath):
            print('setting file not found', self.jsonpath)
            sys.exit(1)
        self.jsondata = myutil.read_jsonfile(self.jsonpath)
        self.docid = self.jsondata.get('docid', '')
        self.sheetid = self.jsondata.get('sheetid', '')
        self.compose_url()
Beispiel #11
0
def test0():
    '''
    read emoji from json file
    and print unicode escape sequence
    '''
    fn = 'emj.json'
    data = read_jsonfile(fn)
    if data is None:
        print('failed to read data from json')
        exit()

    strs = data['string']
    for cc in strs:
        to_from_u16(cc)
Beispiel #12
0
    def __init__(self, prefix, show_image=False):
        self.prefix = prefix
        self.flag_show_image = show_image
        if self.flag_show_image:
            import cv2
            self.imgfont = cv2.FONT_HERSHEY_SIMPLEX
        else:
            self.imgfont = None
        orig_path = '../input_rs/'
        self.imgfile = orig_path + prefix + '_Color.png'
        self.rawfile = orig_path + prefix + '_Depth.raw'
        self.jfile = prefix + '_Color_keypoints.json'
        self.ljson = 'links.json'
        self.proceed = False
        if not self.check_files():
            print('missing files...')
            return
        else:
            self.proceed = True

        linkjson = read_jsonfile(self.ljson)
        self.links = linkjson['link']
        self.json = read_jsonfile(self.jfile)
def main():
    ''' main '''
    data = read_jsonfile(append_path('gmail-app-local.json'))
    if data is None:
        print('cannot fetch key, exit...')
        return
    appkey = data.get('appkey')

    data = read_jsonfile(append_path('pushover-net.json'))
    if data is None:
        print('cannot fetch setting, exit...')
        return
    email = data.get('email')

    print('send content via email gateway by pushover')

    imgurl = 'https://i.imgur.com/ATTKrU7.jpg'
    #yagmail.register('*****@*****.**', appkey)
    yag = yagmail.SMTP('*****@*****.**', appkey)
    to = email
    subject = 'yagmail + pushover @{}'.format(int(time.time()))
    body = 'img @imgur: {}'.format(imgurl)
    img = '/home/rasmus/Pictures/picked/794724259_0f5edb1cd4.jpg'
    yag.send(to=to, subject=subject, contents=[body, img])
Beispiel #14
0
def main():
    ''' main '''
    data = read_jsonfile(append_path('gmail-app-local.json'))
    if data is None:
        print('cannot fetch key, exit...')
        return
    appkey = data.get('appkey')

    data = read_jsonfile(append_path('pushover-net.json'))
    if data is None:
        print('cannot fetch setting, exit...')
        return
    email = data.get('email')

    print('send content via email gateway by pushover')

    imgurl = 'https://i.imgur.com/ATTKrU7.jpg'
    #yagmail.register('*****@*****.**', appkey)
    yag = yagmail.SMTP('*****@*****.**', appkey)
    to = email
    subject = f'yagmail + pushover @{int(time.time())}'
    body = f'img @imgur: {imgurl}'
    img = '/home/rasmus/Pictures/picked/794724259_0f5edb1cd4.jpg'
    yag.send(to=to, subject=subject, contents=[body, img])
Beispiel #15
0
def process_json(prefix):
    imgfont = cv2.FONT_HERSHEY_SIMPLEX
    orig_path = '../input_rs/'
    imgfile = orig_path + prefix + '_Color.png'
    rawfile = orig_path + prefix + '_Depth.raw'
    jfile = prefix + '_Color_keypoints.json'

    if not isfile(imgfile):
        print('{} not found'.format(imgfile))
        return
    if not isfile(jfile):
        print('{} not found'.format(jfile))
        return
    if not isfile(rawfile):
        print('{} not found'.format(rawfile))
        return

    myctr = FindContour()
    myctr.load_file(imgfile, rawfile)
    p1 = ()
    p2 = ()

    json = read_jsonfile(jfile)
    kps = json['people'][0]['pose_keypoints_2d']

    img = cv2.imread(imgfile)
    for idx, kpn in enumerate(KP):
        x = int(kps[idx * 3])
        y = int(kps[idx * 3 + 1])
        pos = (x, y)
        cv2.circle(img, pos, 3, color=(255, 255, 0))
        imgtext = str(kpn).replace('KP.', '')
        #print('{}: {} - ({},{})'.format(idx, imgtext, x, y))
        cv2.putText(img, imgtext, pos, imgfont, 0.8, (0, 0, 255), 2,
                    cv2.LINE_AA)
        if idx == KP.RIGHT_SHOULDER.value:
            p1 = (x, y)
        if idx == KP.LEFT_SHOULDER.value:
            p2 = (x, y)

    #print('show #1')
    #cv2.imshow('img', img)
    #cv2.waitKey(0)

    #print('imshow from listpts.py')
    img2 = myctr.query_length(p1, p2, img=img)
    cv2.imshow('img', img2)
    cv2.waitKey(0)
    def get_apikey(self):
        ''' get apikey '''
        keyfile = 'pushover-net.json'
        home = os.environ.get('HOME')
        keypath = home + '/Private/' + keyfile
        if not myutil.isfile(keypath):
            print('[FAIL] key file not exist: {}'.format(keypath))
            return False
        data = myutil.read_jsonfile(keypath)
        if data is None:
            return False

        self.userkey = data.get('userkey')
        self.apitoken = data.get('apitoken')
        self._device = data.get('device')
        return True
Beispiel #17
0
    def get_apikey(self):
        ''' get apikey '''
        keyfile = 'pushover-net.json'
        home = os.environ.get('HOME')
        keypath = home + '/Private/' + keyfile
        if not myutil.isfile(keypath):
            print(f'[FAIL] key file not exist: {keypath}')
            return False
        data = myutil.read_jsonfile(keypath)
        if data is None:
            return False

        self.userkey = data.get('userkey')
        self.apitoken = data.get('apitoken')
        self._device = data.get('device')
        return True
Beispiel #18
0
 def load_config(self):
     ''' load api key from config '''
     app_conf = 'ggmail.json'
     d = read_jsonfile(app_conf)
     if d is None:
         print('[FAIL] failed to load config')
     else:
         self.auth = d.get('auth')
         if self.auth == 'appkeyfile':
             self.get_appkey(self.append_path(d.get('appkeyfile')))
         else:
             self.oathfile = self.append_path(d.get('oathfile'))
         self.from_ = d.get('from')
         self.to_ = d.get('to')
         self.subject = d.get('subject')
         self.bodyfile = d.get('bodyfile')
Beispiel #19
0
 def load_config(self):
     ''' load api key from config '''
     app_conf = 'ggmail.json'
     d = read_jsonfile(app_conf)
     if d is None:
         print('[FAIL] failed to load config')
     else:
         self.auth = d.get('auth')
         if self.auth == 'appkeyfile':
             self.get_appkey(self.append_path(d.get('appkeyfile')))
         else:
             self.oathfile = self.append_path(d.get('oathfile'))
         self.from_ = d.get('from')
         self.to_ = d.get('to')
         self.subject = d.get('subject')
         self.bodyfile = d.get('bodyfile')
Beispiel #20
0
def test0():
    '''
    read emoji from json file
    and print unicode escape sequence
    '''
    fn = 'emj.json'
    print(f'test0, read {fn}')
    data = read_jsonfile(fn)
    if data is None:
        print('failed to read data from json')
        sys.exit()

    # use **string**
    strs = data['string']
    for i, cc in enumerate(strs):
        print('*' * 10, i, '*' * 10)
        to_from_u16(cc)
Beispiel #21
0
    def get_apikey():
        ''' get api key '''
        keyfile = 'pushover-net.json'
        userkey = None
        apitoken = None
        home = os.environ.get('HOME')
        keypath = home + '/Private/' + keyfile
        if not myutil.isfile(keypath):
            print(f'[FAIL] key file not exist: {keypath}')
            return None, None
        data = myutil.read_jsonfile(keypath)
        if data is None:
            return None, None

        userkey = data.get('userkey')
        apitoken = data.get('apitoken')
        return userkey, apitoken
Beispiel #22
0
    def get_apikey():
        ''' get api key '''
        keyfile = 'pushover-net.json'
        userkey = None
        apitoken = None
        home = os.environ.get('HOME')
        keypath = home + '/Private/' + keyfile
        if not myutil.isfile(keypath):
            print('[FAIL] key file not exist: {}'.format(keypath))
            return None, None
        data = myutil.read_jsonfile(keypath)
        if data is None:
            return None, None

        userkey = data.get('userkey')
        apitoken = data.get('apitoken')
        return userkey, apitoken
Beispiel #23
0
def test(fn):
    ''' test '''
    data = myutil.read_jsonfile(fn)
    if data is None:
        print('[FAIL] read json fail')
    arr = data.get('result').get('random').get('data')
    cnt = 0
    mode = 'wt'
    if myutil.isfile('data.txt'):
        print('file exists, use "at"')
        mode = 'at'

    with open('data.txt', mode) as datafile:
        for elem in arr:
            print('{}'.format(elem), file=datafile)
            cnt += 1
    print('cnt: {}'.format(cnt))
Beispiel #24
0
def test(fn):
    ''' test '''
    data = myutil.read_jsonfile(fn)
    if data is None:
        print('[FAIL] read json fail')
    arr = data.get('result').get('random').get('data')
    cnt = 0
    mode = 'wt'
    if myutil.isfile('data.txt'):
        print('file exists, use "at"')
        mode = 'at'

    with open('data.txt', mode, encoding='utf8') as datafile:
        for elem in arr:
            print(f'{elem}', file=datafile)
            cnt += 1
    print(f'cnt: {cnt}')
Beispiel #25
0
def main():
    ''' main '''
    jsonf = 'setting.json'
    data = myutil.read_jsonfile(jsonf)
    # use get() instead of 'operator []' to prevent exeception
    zfile = data.get('go.py').get('zipfile')

    if not myutil.isfile(zfile):
        print('specified file not found: %s' % zfile)
        return

    zf = zipfile.ZipFile(zfile, 'r')
    print('zipfile: {}\n{}'.format(zfile, '-' * 40))
    flist = zf.namelist()
    for ff in flist:
        print(ff)

    zf.close()
Beispiel #26
0
def load_setting(fn):
    if not myutil.isfile(fn):
        return None, None

    data = myutil.read_jsonfile(SETTING_FN)
    #print(data['fn'])
    fn = data.get('fn')
    print('image fn: {}'.format(fn))
    frame = np.zeros((640, 480, 3), np.uint8)
    if myutil.isfile(fn):
        frame = cv2.imread(fn)
    else:
        print('image file not found: {}'.format(fn))

    rect = data['rect']
    rect = tuple(map(np.int16, rect))
    print('preset loaded')

    return frame, rect
Beispiel #27
0
 def load_config(self):
     ''' load api key from config '''
     home = os.environ.get('HOME')
     app_conf = home + '/Private/mktable_ggmail.json'
     d = read_jsonfile(app_conf)
     if d is None:
         print('[FAIL] failed to load config:', app_conf)
     else:
         self.auth = d.get('auth')
         if self.auth == 'appkeyfile':
             self.get_appkey(self.append_path(d.get('appkeyfile')))
         else:
             self.oathfile = self.append_path(d.get('oathfile'))
         self.from_ = d.get('from')
         self.to_ = d.get('to')
         self.subject = d.get('subject')
         self.bodyfile = d.get('bodyfile')
         #self.load_body()
     self._check()
Beispiel #28
0
    def load_config(self, fn):
        data = myutil.read_jsonfile(fn, debug=True)
        #print(data['fn'])
        fn = data.get('fn')
        frame = np.zeros((640, 480, 3), np.uint8)
        if myutil.isfile(fn):
            frame = cv.imread(fn)
        else:
            print('file not found: {}'.format(fn))
            return None

        rect = data['rect']
        self.focal_length = self.calc_focallength(rect)

        rect = tuple(map(np.int16, rect))
        print(rect)
        self.tracker.clear()
        self.tracker.add_target(frame, rect)
        print('preset loaded')
        return frame
 def load_config(self, fn):
     ''' load api key from config '''
     home = os.environ.get('HOME')
     app_conf = home + '/set-send-attach.json'
     print('read settings from:', app_conf)
     d = read_jsonfile(app_conf)
     if d is None:
         print('[FAIL] failed to load config:', app_conf)
     else:
         auth_method = d.get('auth')
         if auth_method == 'appkeyfile':
             self.get_appkey(self.append_path(d.get('appkeyfile')))
         else:
             self.oathfile = self.append_path(d.get('oathfile'))
         self.from_ = d.get('from')
         self.to_ = d.get('to')
         self.subject = d.get('subject')
         if fn:
             print('body file is override by:', fn)
             self.bodyfile = fn
         else:
             self.bodyfile = d.get('bodyfile')
         #self.load_body()
     self._check()
Beispiel #30
0
 def load_config(self, fn):
     ''' load config '''
     data = myutil.read_jsonfile(fn)
     if data is None:
         return
     self.message = data.get('s')
 def get_appkey(self, fn):
     ''' get appkey from fn '''
     d = read_jsonfile(fn)
     self.appkey = d.get('appkey')
Beispiel #32
0
 def get_appkey(self, fn):
     ''' get appkey from fn '''
     d = read_jsonfile(fn)
     self.appkey = d.get('appkey')
Beispiel #33
0
def main(argv: List) -> None:
    ''' main '''
    for f in argv:
        js = read_jsonfile(f)
        print(f'len of keys in file {f}: {len(js)}')
Beispiel #34
0
 def load_json(self):
     ''' load json '''
     self.data = read_jsonfile('bpmf.json')
Beispiel #35
0
 def _load_conf(self):
     ''' load conf '''
     h = get_home()
     p = h + '/Private/working-days.json'
     self.data = read_jsonfile(p)
Beispiel #36
0
 def load_config(self, fn):
     ''' load config '''
     data = myutil.read_jsonfile(fn)
     if data is None:
         return
     self.message = data.get('s')