Giter VIP home page Giter VIP logo

weatherreport's Introduction

WeatherReport

I use this repository on a vps to send a message on time everyday.

The repository use 3 python modules:

weather-api: https://github.com/AnthonyBloomer/weather-api

twilio: https://github.com/twilio/twilio-python

apscheduler: https://github.com/agronholm/apscheduler


Enviroment build

  • Virtualenv

Install virtualenv:

pip3 install virtualenv

Make project:

mkdir myproject

cd myproject/

Make virtual python3 environment:

virtualenv --no-site-packages venv

Actvivate environment:

soruce source venv/bin/activate

By the way, quit environment:

deactivate
  • Modules

Install weather-api:

pip3 install weather-api

Install twilio:

pip3 install twilio

Instal apscheduler:

pip3 install apscheduler

Coding

  • Get weather from yahoo

    weather = Weather(unit=Unit.CELSIUS)
    location = weather.lookup_by_location('shanghai') 
    condition = location.condition
    forecasts = location.forecast 
    

    Location.forecast returns a forecast list, forecast[0] is today.

  • Send message

    account_sid = '' 
    auth_token = ''  
    client = Client(account_sid, auth_token)
    
    message = client.messages.create(
        from_='', 
        body=text,
        to='' # the number when you sign in, trial account can only send this number
    )
    

    Variable account_sid and auth_token are you get from twilio.com.

    Variable from_ is the number that twilio.com gives you.

    Variable to is the number when you sign in, trial account can only send this number.

  • Autorun

    scheduler = BlockingScheduler()
    scheduler.add_job(function, 'cron', day_of_week='0-6', hour=7, minute=00) 
    scheduler.start()
    

    Function is you want to do on time.

    Cron means period.

    For example

    day_of_week='0-6', hour=7, minute=00
    

    It means we will do the function everyday at 7:00am.

Finally, we can receive the weather message on our phones everymoring at 7:00am.

weatherreport's People

Contributors

februarysea avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.