Multi-tasking timed send Python3

Source: Internet
Author: User

Regular send, weather, text information, sent to the designated friends, groups.

Schedule Timing
1 ImportRequests2  fromRequestsImportExceptions3  fromUrllib.requestImportUrlopen4  fromBs4ImportBeautifulSoup5 ImportRe6  fromWxpyImport*7 ImportSchedule8 Import Time9  Ten   One #Bot=bot (cache_path=true) #登陆网页 and save the login status Abot = bot (console_qr=2,cache_path="BOTOO.PKL")#Linux dedicated, pixel QR code -   - defsendblogmsg (content): the     #Search for your friends, note that you need +u before Chinese characters -My_friend = Bot.friends (). Search (U'Wang Lin Jay') [0] - my_friend.send (content) -  +My1_friend = Bot.friends (). Search (U'hrs') [0] - my1_friend.send (content) +  AMy_group = Bot.groups (). Search (U'Chat robot Test') [0] atMy_group.send (content)#Send weather forecast -  -  -  -My1_group = Bot.groups (). Search (U'Test') [0] -My1_group.send (content)#Send weather forecast in   - defJob (): toResp=urlopen ('http://www.weather.com.cn/weather/101010100.shtml') +Soup=beautifulsoup (RESP,'Html.parser') -Tagtoday=soup.find ('P', class_="tem")#The first P-tag containing the class= "TEM" is the label that holds today's weather data the     Try: *Temperaturehigh=tagtoday.span.string#Sometimes the maximum temperature is not displayed, which is replaced by the highest temperature of the next day.  $     exceptAttributeerror as E:Panax NotoginsengTemperaturehigh=tagtoday.find_next ('P', class_="tem"). span.string#get the highest temperature of the next day instead -   theTemperaturelow=tagtoday.i.string#get the lowest temperature +Weather=soup.find ('P', class_="WEA"). String#Get the weather AContents ='Beijing'+'\ n'+'Maximum temperature:'+ Temperaturehigh +'\ n'+'Minimum temperature:'+ Temperaturelow +'\ n'+'weather:'+Weather the        #RESULT3 = ' Minimum temperature: ' + Temperaturelow +     #print (' Minimum temperature: ' + Temperaturelow) -     #print (' max temperature: ' + Temperaturehigh) $    #print (' weather: ' + weather) $ sendblogmsg (contents) -  -  the defsendblogmsg_1 (content): -     #Search for your friends, note that you need +u before Chinese charactersWuyiMy_friend = Bot.friends (). Search (U'Wang Lin Jay') [0] the my_friend.send (content) -  Wu defjob_1 (): -  About     ifbot = =None: $ login_wechat () -  -Contents ='rest early, good night??'  -        #RESULT3 = ' Minimum temperature: ' + Temperaturelow A     #print (' Minimum temperature: ' + Temperaturelow) +     #print (' max temperature: ' + Temperaturehigh) the    #print (' weather: ' + weather) - sendblogmsg_1 (contents) $  the  the  the  the #timed -Schedule.every (). day.at ("22:50"). Do (Job)#requires the job () function to be executed 12:30 every day inSchedule.every (). day.at ("22:50"). Do (job_1)#requires the job () function to be executed 12:30 every day the  whileTrue: theSchedule.run_pending ()#Make sure the schedule is always running AboutTime.sleep (1) theBot.join ()#ensure that the above code continues to run

Multi-tasking timed send Python3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.