Page 2 of 2

Re: Automatic weather tweets

Posted: Friday 31 January 2014 8:09
by mbliek
Your welcome.
You can take a look at some other scripts with Python instead of bash.

Re: Automatic weather tweets

Posted: Friday 31 January 2014 9:26
by elythomaslumber
Well, but finally I will end up on the same "locked" login-page I think...
Anyway this would be the only reason why I should use Twitter :D Therefore I was very fascinated by your idea!

Currently I'm working on a script which will:
1. send me a complete weather forecast from wunderground by email for the next 6h, 12h, 24h, 48h -> I tried to send to domoticz data-base but it chrashed and I will never it touch again :evil:
(/json.htm?type=command&param=udevice&idx=10&nvalue=0&svalue=12.3;45;2")

2. and a little bit crazy...switch on a APPLamp (little lamp close to my TV) once a hour showing me temp, rain and wind forecast in the next 6 hours by different coloure and flash effects...

Re: Automatic weather tweets

Posted: Friday 31 January 2014 22:48
by mbliek
The python scripts using an other method. There was a script on the old forum. But that forum is not available anymore.

Re: Automatic weather tweets

Posted: Saturday 01 February 2014 10:18
by elythomaslumber
I'm still working on a solution and feel like Edison "I know 1000 ways how it will not work." :lol:

Currently I'm using the -v parameter in curl to show the complete handshake between Twitter and the script showing nothing negativ so far I can see. (By the way, meanwhile there is non more a CAPTCHA lock!)
Also I stored every variable in a text-file to see the data content.

Everything looks fine whis exception of the variable $update which contents:
Invalid request parameters
This code does the problem I think:

Code: Select all

update=$(curl -v -s -b "cookie.txt" -c "cookie.txt" -L --sslv3 -A "$uagent" -d "authenticity_token=$tweettoken&tweet[text]=$tweet&tweet[display_coordinates]=false" "https://mobile.twitter.com/")
The problem seems to be here: [display_coordinates].

Regards

Hardy

For those who read this forum the current status:
- using the bash scripts was finally not successful for me
- a PHP script is running very well
- the PHP script has to be started by a bash
- fully integration in a single script is under development
- current status can be seen here: https://twitter.com/SGforecast

Re: Automatic weather tweets

Posted: Wednesday 03 December 2014 17:52
by schmm
I had the last days continuously problems with tweeting with this script.

I did not receive any errors, but is didn't tweet anything.

I altered the script and i'm now using Twython to tweet. You only have to make an application account in twitter and with the api key's you are able to tweet on a easy way!

Re: Automatic weather tweets

Posted: Friday 05 December 2014 13:56
by WpeterW
Yesterday I posted a reply in this thread, just mentioning how I have achieved this using Python. I posted a link to my twitter-profile: http://twitter.com/hetweerinannen

After that my account and ip were banned. Can some mod explain me why ? I've read the forum-rules and I can't think of a rule I may have violated. Thanks.

Ps: the post on the old forum, referred to in this thread, was my contribution.

Re: Automatic weather tweets

Posted: Friday 05 December 2014 14:38
by mbliek
Sorry. Don't know why you have been banned. The comment is "cool down" don't know why?

Re: Automatic weather tweets

Posted: Friday 05 December 2014 14:45
by WpeterW
"Cool down" ? Who modded that ?

Re: Automatic weather tweets

Posted: Friday 05 December 2014 14:46
by mbliek
gizmocuz. You should ask him.

Re: Automatic weather tweets

Posted: Sunday 07 December 2014 8:48
by WpeterW
I did. No response.

Re: Automatic weather tweets

Posted: Monday 11 May 2015 14:40
by ironleg
I've tried to have my domoticz installation send automatic weather tweets, but no luck so far.

To trouble shoot the problem i commented out the lines where the tweet variable is set, en changed is to:

Code: Select all

tweet="hallo wereld"
when executing the script the posting to twitter seems to be ok:

Code: Select all

[+] Fetching twitter.com...
[+] Submitting the login form...
[+] Getting compose tweet page...
[+] Posting a new tweet: hallo wereld...
[+] Logging out...
But stil nothing is posted to my twitter account.

I've also looked at tweethon but i can't find any documentation to get this working.

Can someone help me further with this?

Re: Automatic weather tweets

Posted: Tuesday 12 May 2015 9:13
by mbliek
Twitter don't accept this type of login this script uses. It don't give any errors.

Re: Automatic weather tweets

Posted: Wednesday 13 May 2015 9:05
by mvveelen
Nice to see this :) And so close to where I love :mrgreen:

Re: Automatic weather tweets

Posted: Saturday 07 May 2016 13:49
by Siewert308SW
I know, old topic but wanted to share experience with this script.
Last night i wanted to be able to make my Raspi tweet our local weather, just for fun ;-)
Well seems twitter doesn't allow the method as describe here.
So i took a other approach which works flawless.
Maybe not the cleanest script but it works.

@1 i created a new app via https://apps.twitter.com/app/new

@2 i installed the following extra packages on my Rapsberry
sudo apt-get install python-setuptools
sudo easy_install pip
sudo pip install tweepy

@3 i create a new python script called weer.py
You need to fill the keys below as create @ https://apps.twitter.com/app/new
The weather-tweet.txt is a file where your future tweet is stored and this scripts needs it to tweet.
Also made this script executable.

Code: Select all

#! /usr/bin/env python
import tweepy
from datetime import datetime

API_KEY = ' '
API_SECRET = ' '
ACCESS_TOKEN = ' '
ACCESS_TOKEN_SECRET = ' '

auth = tweepy.OAuthHandler(API_KEY, API_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)

tempfile = open("/mnt/usbstorage/tweets/weather-tweet.txt") 
thetext = tempfile.read()
tempfile.close()

api.update_status(thetext)

@4 I created a bash script which is executable.
And made a cron for every hour. */60 * * * * sudo bash /home/pi/domoticz/scripts/bash/weer_tweet.sh
It scraps the data from my sensors in the garden but it will work with weatherunderground also.
Code below has the same idea as the script in this thread.

Code: Select all

#!/bin/bash

thermo=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=37"`
echo $thermo > /mnt/usbstorage/tweets/weather-data.txt
temperature=`cat /mnt/usbstorage/tweets/weather-data.txt | awk -F: '{print $17, $18}' | awk '{print $3}' | sed 's/\"//g'`

hygro=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=37"`
echo $hygro > /mnt/usbstorage/tweets/weather-data.txt
hygro=`cat /mnt/usbstorage/tweets/weather-data.txt | awk -F: '{print $18, $19}' | awk '{print $3}' | sed 's/\"//g'`

rain=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=40"`
echo $rain > /mnt/usbstorage/tweets/weather-data.txt
rain=`cat /mnt/usbstorage/tweets/weather-data.txt | awk -F: '{print $13, $14}' | awk '{print $3}' | sed 's/\"//g' | sed 's/,//g'`

wind=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=38"`
echo $wind > /mnt/usbstorage/tweets/weather-data.txt
dir=`cat /mnt/usbstorage/tweets/weather-data.txt | awk -F: '{print $20, $21}' | awk '{print $3}' | sed 's/\"//g' | sed 's/,//g'`
speed=`cat /mnt/usbstorage/tweets/weather-data.txt | awk -F: '{print $22, $23}' | awk '{print $3}' | sed 's/\"//g' | sed 's/,//g'`
chill=`cat /mnt/usbstorage/tweets/weather-data.txt | awk -F: '{print $15, $16}' | awk '{print $3}' | sed 's/\"//g' | sed 's/,//g'`

baro=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=37"`
echo $baro > /mnt/usbstorage/tweets/weather-data.txt
baro=`cat /mnt/usbstorage/tweets/weather-data.txt | awk -F: '{print $14, $15}' | awk '{print $3}' | sed 's/\"//g' | sed 's/,//g'`

zicht=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=41"`
echo $zicht > /mnt/usbstorage/tweets/weather-data.txt
zicht=`cat /mnt/usbstorage/tweets/weather-data.txt | awk -F: '{print $16, $17}' | awk '{print $3}' | sed 's/\"//g' | sed 's/,//g'`

uv=`curl "http://127.0.0.1:8080/json.htm?type=devices&rid=39"`
echo $uv > /mnt/usbstorage/tweets/weather-data.txt
uv=`cat /mnt/usbstorage/tweets/weather-data.txt | awk -F: '{print $16, $17}' | awk '{print $3}' | sed 's/\"//g' | sed 's/,//g'`

echo -ne "#Zoutkamp\nTemp: $temperature C\nWindchill: $chill C\nLuchtvochtigheid: $hygro %\nNeerslag: $rain mm\nWind: $dir / $speed km/h\nBaro: $baro hPa\nZicht: $zicht km\nUV: $uv" > /mnt/usbstorage/tweets/weather-tweet.txt

sudo python /home/pi/domoticz/scripts/python/weer.py
example: https://twitter.com/ZKWeerTweets