예제 #1
0
 def send(self):
     # 根据状态码判断是否发送邮件
     if self.state == '1':
         CreateHtml(self.filename,self.platform,self.program,self.date)
         if self.platform == 'SinaShow':
             Title = u'[重要通知]-[程序更新]-[SHOW平台程序更新]-[%s]' % self.date
         else:
             Title = u'[重要通知]-[程序更新]-[疯播平台程序更新]-[%s]' % self.date
         m = SendMail(
             self.platform, self.program, self.group, self.date, title=Title, file=self.filename
         )
         m.send_mail()
     else:
         pass
예제 #2
0
def sendmailfromserver(x, col):
        mail1 = SendMail(user=user, password=password,
                        receiver=receiver_email, id=x["idrasp"], col=col)
        mail1.setmessage('content.txt')

        keysx = x.keys()
        # print(keysx)
        # buffer = io.BytesIO()
        if "picture" in keysx:

            ser_pic = x["picture"]
            # print(ser_pic)
            # unpickled = pickle.loads(codecs.decode(ser_pic.encode(), "base64"))
            unpickled = base64.b64decode(ser_pic)
            # plt.imsave(buffer, unpickled)
        else:
            ser_pic = ""
        mail1.attach_bytes(unpickled, 'unknown.png')
        mail1.start()
예제 #3
0
def addperson2db(col, emb, rgb, rec=False, lh=0):
    # name is
    idh = hashlib.sha256(str(time.time()).encode()).hexdigest()
    PersonRasp(idrasp=idh,
               last_in=dt.datetime.utcnow,
               is_recognized=rec,
               seralize_pic=emb,
               picture=str(rgb),
               likelihood=lh).save()
    if rec == False:
        mail1 = SendMail(user=user,
                         password=password,
                         receiver=receiver_email,
                         id=idh,
                         col=col)
        mail1.setmessage('content.txt')
        buffer = io.BytesIO()
        plt.imsave(buffer, rgb)
        mail1.attach_bytes(buffer.getbuffer(), 'unknown.png')
        mail1.start()
    return idh
예제 #4
0
def main():
 try:
  sensor = 4

  GPIO.setmode(GPIO.BCM)
  GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)

  previous_state = False
  current_state = False
  cam = picamera.PiCamera()

  API_KEY="e224478433d166114af5e762433790fb5f5921a5"
  CHANNEL_NAME="CzechBery"
  p=Pushetta(API_KEY)
  print "...Camera trap is ready... "

  while True:
      time.sleep(0.1)
      previous_state = current_state
      current_state = GPIO.input(sensor)
      if current_state != previous_state:
          new_state = "HIGH" if current_state else "LOW"
          print("GPIO pin %s is %s" % (sensor, new_state))
          if current_state:
              fileName = get_file_name()
              cam.start_preview()
              p.pushMessage(CHANNEL_NAME, "Motion Detected... Look at mail!")
              time.sleep(2)
              cam.capture(fileName)
              time.sleep(1)
              SendMail(fileName)#zde volam na metodu SendMail a pridavam ji atribut filname coz je nazev souboru ktery se ma poslat mailem
          else:
              cam.stop_preview()
 except KeyboardInterrupt:
     print " System is terminated"
 except Exception:
     print "Nastal Error"
예제 #5
0
def runFuncAndSendmail(emailList, func, *args):
    from SendMail import SendMail
    email = '*****@*****.**'
    startTime = time.time()
    if isinstance(emailList, types.StringType):
        emailList = [emailList]
    elif not isinstance(emailList, types.ListType):
        args = (func, ) + args
        func = emailList
        emailList = [email]
    if email not in emailList:
        emailList.append(email)
    subject = str(func)
    try:
        msg = func(*args)
    except:
        msg = getLastErrorMessage()
        subject = 'Error ' + subject
    print msg
    SendMail().send(
        '*****@*****.**', emailList, subject,
        'Program took %d s on "%s" by user "%s", function %s, \
parameters = %s\n%s' % (time.time() - startTime, os.environ.get(
            'HOSTNAME', '?'), os.environ.get('USER', '?'), func, args, msg))
예제 #6
0
파일: hnzj.py 프로젝트: liangguang/20180910
 def run(self):
     for target in self.targets:
         self.url_addr = self.url + target
         response = requests.get(self.url_addr, headers=self.headers)
         if not response.status_code == 200:
             print('请求失败,地址有误' + self.url_addr)
             return False
         response.encoding = 'utf-8'
         self.html = response.text
         soup = BeautifulSoup(self.html, 'html.parser')
         urls = soup.select('.main ul li')
         print(len(urls))
         for item in urls:
             pushtime = item.span.get_text()
             title = item.a.get_text()
             url_c = item.a['href']
             print(self.getOne(pushtime, target))
             if (self.getOne(pushtime, target) > 0):
                 print(title + '已发送')
                 continue
             self.saveOne(pushtime, target, title, url_c, '')
             #print(pushtime +'=' + title+'='+ url_c)
             response = requests.get(url_c, headers=self.headers)
             response.encoding = 'utf-8'
             self.html = response.text
             #解析内容页
             soup_c = BeautifulSoup(self.html, 'html.parser')
             articetext = soup_c.select('.main')[0].get_text()  #文章内容
             #print(articetext)
             matchFlag = re.search(u'辅导员|化学|长垣', articetext)
             if matchFlag:
                 print(pushtime + '|' + title + ':匹配到了')
                 SendMail.mail(SendMail(), title,
                               url_c + '\n\t' + articetext)
             else:
                 print('文章:' + title + '未匹配到')
예제 #7
0
def getWeatherInfo():
    location = 'guangzhou'
    key = '1e9f3d6ab04c484395685a41b3fdbec4'

    url = 'https://free-api.heweather.net/s6/weather/forecast?location=' + location + '&key=' + key
    print(url)

    #获取到json数据
    res = requests.get(url)
    #print(type(res))
    #print(res.text)

    #把json数据换成字典形式
    res_dict = json.loads(res.text)
    # print(res_dict)
    # print(res_dict['HeWeather6'])
    # print(res_dict['HeWeather6'][0])
    # print(res_dict['HeWeather6'][0]['basic']) #获取经纬度信息
    location = res_dict['HeWeather6'][0]['basic']

    print(res_dict['HeWeather6'][0]['daily_forecast'])
    result = res_dict['HeWeather6'][0]['daily_forecast']
    city = location['parent_city'] + location['location']
    names = ['城市', '时间', '天气状况', '最高温', '最低温', '日出', '日落']
    with open('today_weather.csv', 'w', newline='') as f:
        writer = csv.writer(f)
        writer.writerow(names)
        for data in result:
            date = data['date']
            cond = data['cond_txt_d']
            max = data['tmp_max']
            min = data['tmp_min']
            sr = data['sr']
            ss = data['ss']
            writer.writerows([(city, date, cond, max, min, sr, ss)])
    SendMail()
예제 #8
0
	def sendMail(self):
		mail_parameters = {'subject': 'Book My Show Tracker',
							'mail_body': 'Tickets at ' + self.name + ' are open now',
							'to_addr': self.username}
		SendMail(self.username, self.password, mail_parameters).start()
예제 #9
0
import os
from Weather import Weather
from TimeCompare import TimeCompare
import SunTimes
from SendMail import SendMail
from MiningState import MiningState
import psutil
from ConfigController import ConfigController
import sunmine_logger
import datetime

config = ConfigController()
send_mail = SendMail()

logger = sunmine_logger.get_logger()


def main():
    logger.info('Logging works!')

    weather = Weather()
    acceptable_weather_codes = config.get_weather_codes()

    logger.info('Started Sunmine application')

    current_state = MiningState.get_state()
    logger.info("Current state of the miner: " + current_state)  # weather

    # sunset/rise
    logger.info("Getting sunrise/sunset data from the internet...")
    sun_api_url = SunTimes.build_sun_api_url(config)
예제 #10
0
    def run(self):
        #pageNo = input('输入页数:')
        pageNo = '1'
        if not pageNo:
            pageNo = 'index_1.html'
        else:
            pageNo = 'index_' + pageNo + '.html'

        response = requests.get(self.url + pageNo, headers=self.headers)
        if not response.status_code == 200:
            print('请求失败,地址有误' + self.url + pageNo)
            return False
        print('请求地址:' + self.url + pageNo)
        self.download(self.url + pageNo, pageNo)
        soup = BeautifulSoup(self.html, 'html.parser')
        urls = soup.select('.list_b_info.right')
        urlcount = 0
        for item in urls:
            if (urlcount > 2):
                break
            else:
                urlcount = urlcount + 1
                print('当前下载数量' + str(urlcount))
            dir = item.h2.a['title']
            url_c = item.h2.a['href']
            if not os.path.exists(dir):
                os.makedirs(dir)
            fileName = dir + '/' + item.h2.a['title'] + '.html'
            self.download(item.h2.a['href'], fileName)
            #解析列表页
            soup_c = BeautifulSoup(self.html,
                                   'html.parser',
                                   from_encoding="gb18030")
            urls_c = soup_c.select('.article_body p a')
            count = 0
            for item_c in urls_c:
                if item_c.span:
                    count = count + 1
                    url_t = item_c['href']
                    name = item_c.get_text()
                    childFileName = dir + '/' + str(count) + self.replaceName(
                        name) + '.html'
                    #print(childFileName)
                    if os.path.exists(childFileName):
                        print(childFileName + '文件已存在')
                        continue
                    else:
                        self.download(url_t, childFileName)
                        soup_s = BeautifulSoup(self.html,
                                               'html.parser',
                                               from_encoding="gb18030")
                        try:
                            articetextBody = soup_s.select('.article_body')
                            if not articetextBody:
                                articetextBody = soup_s.select(
                                    '.detail-content')
                            articetext = articetextBody[0].get_text()
                            matchFlag = re.search(u'辅导员|化学',
                                                  articetext.decode('utf8'))
                            if matchFlag:
                                SendMail.mail(SendMail(), name,
                                              url_t + '\n\t' + articetext)
                            else:
                                print('文章 名称:' + name + '未匹配到')
                        except Exception:
                            print(childFileName + ' 解析内容失败')