Esempio n. 1
0
def sendMail(to=MailToList,
             subject=None,
             contents=None,
             attachments=None,
             cc=None,
             bcc=None,
             preview_only=False,
             headers=None,
             newline_to_break=True):
    user = config.read(config_section='Email', config_option='user')
    password = config.read(config_section='Email', config_option='password')
    host = config.read(config_section='Email', config_option='host')
    port = config.read(config_section='Email', config_option='port')
    try:
        with email.SMTP(user=user, password=password, host=host,
                        port=port) as m:
            m.send(to=to,
                   subject=subject,
                   contents=contents,
                   attachments=attachments,
                   cc=cc,
                   bcc=bcc,
                   preview_only=preview_only,
                   headers=headers,
                   newline_to_break=newline_to_break)
            logger.info(f'邮件发送成功!to:{to}')
    except Exception as e:
        logger.error(e)
Esempio n. 2
0
 def read(self, config_section, config_option):
     try:
         self.config_section = config_section
         self.config_option = config_option
         self.config_value = self.config.get(section=self.config_section,
                                             option=self.config_option)
         return self.config_value
     except Exception as e:
         logger.error(e)
Esempio n. 3
0
def getAlbum(savefilename, playlistindex, tracklist, flags, genre='', reset=True):
   metadata, tracklist = tracklist[0], tracklist[1:]
   metadata = list(metadata) + [genre]
   s = ParseTables.writeextendedtracklist("%s.txt" % os.path.join(dumpdir, savefilename), flags, metadata, tracklist)
   logger.info("\n%s" % s)
   
   playlistindex = int(playlistindex)
   albumlen = sum((s[1] for s in tracklist))
   logger.info("Length: %d" % albumlen)
   
   if playlistindex > vs['Constants']['maxplaylists']:
      logger.error("Playlist index must be %d or below" % vs['Constants']['maxplaylists'])
      sys.exit(2)

   MouseDo(' '.join([Wait(2),
                     Window(1), 
                     Move(*vs['Audacity']['record']), 
                     Click(), 
                     Wait(5), 
                     Window(0), 
                     Play(playlistindex), 
                     Wait(2),
                     Move(*vs['Grooveshark']['safespot'])
                    ]))
   if albumlen > 3600:
      Idle(albumlen + 30)
   else:
      time.sleep(albumlen + 30)
   MouseDo(' '.join([Move(100,100),
                     Wait(1),
                     Window(1),
                     Move(*vs['Audacity']['stop']),
                     Click()]))
   if reset:
      savepath = os.path.join(dumpdir, "%s.wav" % savefilename)
      MouseDo(' '.join([Move(*vs['Audacity']['file']),
                        Click(),
                        Move(*vs['Audacity']['export']),
                        Click(),
                        Type(savepath),
                        Enter(),
                        Enter(),
                        Move(*vs['Audacity']['middle']),
                        Wait(albumlen / 35),
                        Click(),
                        Toggle('c'),
                        Type('z'),
                        Toggle('c'),
                        Window(0),
                        Move(*vs['Grooveshark']['empty']),
                        Click(),
                        Wait(1),
                        Window(2)
                       ]))
      if split:
         splitTrack(savefilename)
Esempio n. 4
0
def request(url):
    try:
        res = requests.get(url)
        if res:
            return res
        else:
            return None
    except Exception as e:
        logger.error(msg=e)
        return None
Esempio n. 5
0
def checkcommands(c, pr=True):
   i = 0
   for savefilename, genre, playlistindex, metadata, flags in c:
      status, e = ParseTables.canread(metadata)
      good = True
      if not status:
         logger.error("Can't read metadata from %s. (%s)" % (metadata, str(e)))
         good = False
      elif pr:
         Util.foldtracklist(e, genre, flags)
         logger.info("%s\n%s\n" % (playlistindex, '\n'.join(['\t'.join(map(str, row)) for row in e])))
      i += 1
   return good
Esempio n. 6
0
def LoadImage(image_url: str):
    res = request(image_url)
    retry = 1
    while not res:
        logger.error(msg=f"请求 [ {image_url} ] 出现网络出现波动,请在重试第 {retry} 次!")
        if retry <= max_retry:
            res = request(image_url)
            retry += 1
        else:
            logger.critical(msg=f"网络访问异常!")
            return res
    image = Image.open(BytesIO(res.content))
    return image
Esempio n. 7
0
 def __init__(self, config_path):
     # 配置文件参数
     self.config_path = config_path
     self.config_section = None
     self.config_option = None
     self.config_value = None
     # 加载配置文件
     try:
         self.config = ConfigParser()
         self.config.read(config_path, encoding='utf-8')
     except FileNotFoundError as f:
         logger.error(f)
     except Exception as e:
         logger.error(e)
Esempio n. 8
0
 def save(self, config_section, config_option, config_value):
     try:
         self.config_section = config_section
         self.config_option = config_option
         self.config_value = config_value
         self.config.set(section=self.config_section,
                         option=self.config_option,
                         value=self.config_value)
         with open(self.config_path, 'w') as config_file:
             self.config.write(config_file)
     except FileNotFoundError as f:
         logger.error(f)
     except Exception as e:
         logger.error(e)
Esempio n. 9
0
def get():
    try:
        api_list = {
            'weather':
            f'http://api.tianapi.com/txapi/tianqi/index?key={Key}&city={city_name}',
            'bulletin':
            f'http://api.tianapi.com/bulletin/index?key={Key}',
            'journalism':
            f'http://api.tianapi.com/generalnews/index?key={Key}&num=10',
            'it_news':
            f'http://api.tianapi.com/it/index?key={Key}&num=10',
            'sentence':
            f'http://api.tianapi.com/txapi/dictum/index?key={Key}&num=1'
        }
        res_list = {
            'weather': None,
            'bulletin': None,
            'journalism': None,
            'it_news': None,
            'sentence': None
        }
        for api in api_list.items():
            module, url = api
            res = request(url)
            retry = 1
            while not res:
                if retry <= max_retry:
                    logger.error(
                        msg=f"请求 {module} [ {url} ] 出现网络出现波动,请在重试第 {retry} 次!")
                    res = request(url)
                    retry += 1
                else:
                    logger.critical(msg=f"网络访问异常!")
                    break
            if res:
                res = res.json()
                if res['code'] == 200 and res['msg'] == 'success':
                    res_list[module] = res['newslist']
                else:
                    logger.error(msg=f'请求失败\n{res}')
                    if res['code'] == 230:
                        return res_list
        return res_list
    except Exception as e:
        logger.error(e)
Esempio n. 10
0
def SetClipBoard(text):
    try:
        pyperclip.copy(text)
    except Exception as e:
        logger.error(e)
Esempio n. 11
0
def DownloadImage(immage_url: str, image_name: str):
    try:
        path, message = urlretrieve(immage_url, f'./Export/{image_name}.png')
        return path
    except Exception as e:
        logger.error(e)
Esempio n. 12
0
def testsplit(realtracks, wavfilename):
   tracks = WAVSplitter(wavfilename).parsewav()
   for i, t in enumerate(tracks):
      if t['sharpstart']:
         if t['tstart'] < realtracks[2*i][0] or t['tstart'] > realtracks[2*i][-2]:
            if not realtracks[2*i][-1] == '|':
               logger.error("Track %d NOT smooth start as expected." % i)
            logger.error("Track %d sharp start (%d) NOT found in expected interval [%d, %d]" % (i, t['tstart'], realtracks[2*i][0], realtracks[2*i][-2]))
         else:
            logger.info("Track %d start found successfully." % i)
      else:
         failed = False
         if t['tstart'] > realtracks[2*i][-2]:
            logger.error("Track %d smooth start (%d) NOT found in expected interval [, %d]" % (i, t['tstart'], realtracks[2*i][0]))
            failed = True
         if not realtracks[2*i][-1] == '<':
            logger.error("Track %d NOT sharp start as expected." % i)
            failed = True
         if not failed:
            logger.info("Track %d start found successfully." % i)
         
      end = t['tend'] - 1
      if t['sharpend']:
         if end < realtracks[2*i+1][0] or end > realtracks[2*i+1][-2]:
            if not realtracks[2*i+1][-1] == '|':
               logger.error("Track %d NOT smooth end as expected." % i)
            logger.error("Track %d sharp end (%d)  NOT found in expected interval [%d, %d]" % (i, end, realtracks[2*i+1][0], realtracks[2*i+1][-2]))
         else:
            logger.info("Track %d end found successfully." % i)
      else:
         failed = False
         if end < realtracks[2*i+1][0]:
            logger.error("Track %d smooth end (%d)  NOT found in expected interval [%d, ]" % (i, end, realtracks[2*i+1][0], realtracks[2*i+1][-2]))
            failed = True
         if not realtracks[2*i+1][-1] == '>':
            logger.error("Track %d NOT sharp end as expected." % i)
            failed = True
         if not failed:
            logger.info("Track %d end found successfully." % i)