Author Topic: Problems with Scripts and Email to Twitter and Facebook  (Read 12247 times)

meteoperugia

  • Gentle Breeze
  • **
  • Posts: 79
    • DW0950
    • IPERUG54
    • MeteoPerugia
  • Station Details: Davis Vantage Pro2, iMac (Retina 5K, 27-inch, Late 2015), WeatherCat 3
Problems with Scripts and Email to Twitter and Facebook
« on: November 08, 2013, 10:50:58 AM »
Hi everybody.
There was a script uploaded by a american member (Rick, GoldenGoose) that with Cronnix allowed to upload WeatherCat data (daily, weekly, monthly data, webcam images, statistics…etc) to Twitter. Now Twitter API version is uploaded to from 1 to 1.1 and it doesn't run since last june.
I've tried to update API, Python, Tweepy….but NO WAY ti upload data in that way.
I know there is another script (Thanks Eduard!) but with last method I was able to custom different scripts at different time to upload different data to Twitter. I need it because Twitter repeat messages to my FaceBook weather page.
I will be glad if somebody could explain me how to run that script again.
Script was called twitter_API.php and was following:

Quote
<meta name="robots" content="noindex,nofollow">
   
#!/usr/bin/php
<?php
// For Account:   'Twitter Account Name Goes Here'

// Make sure these files are in a directory called "lib"
require "/your LWC uploads folder name/lib/EpiCurl.php";
require "/your LWC uploads folder name/lib/EpiOAuth.php";
require "/your LWC uploads folder name/lib/EpiTwitter.php";

// Settings required for each account/user
define(CONSUMER_KEY,"Your Key Code goes here between quotes");
define(CONSUMER_SECRET,"Your Secret");
define(USER_TOKEN,"Your Token");
define(USER_SECRET,"Your User Secret");

//Text to be updated on twitter
$status = "Temp: STAT$TEMPERATURE:CURRENT$ F * HeatIndex: STAT$HEATINDEX:CURRENT$ F * Hum: STAT$EXTHUMIDITY:CURRENT$% * Dew: STAT$DEWPOINT:CURRENT$ F * Baro: STAT$PRESSURE:CURRENT$ PRESSUREUNITS$ * UV: STAT$UV:CURRENT$ * Rain: STAT$RAIN:TOTAL:TODAY$ RAINUNITS$ @ t12$ ";

// Format text as utf8 and chomp at 140 chars
$text = utf8_encode(substr($status,0,140));

$twitterObj = new EpiTwitter(CONSUMER_KEY,CONSUMER_SECRET,USER_TOKEN,USER_SECRET);
$x = $twitterObj->post_statusesUpdate(array('status' => $status));

// Test whether the tweet was posted successfully.
if ($x->id) {
   echo "Tweet Posted: ".$x->id."\n";
} else {
   echo "Error Posting Tweet\n";   
}   

?>

Thanks in advance!  ;)

ANOTHER QUESTION (to Stu)

I send WeatherCat email alerts to a FaceBook (again) upload address but Facebook shows only the email header (object) but not the text where are advices and data. There is a way to add data do the object?
Ex: Now WC send a message where in the title is "HEAVY RAIN ALARM" and in the text are data to see HOW HEAVY the rain is (rain rate 100mm/h). Facebook receive email but show only "HEAVY RAIN ALARM". I would add to the title rain rate (or other weather data) in order to se on Facebook the message "HEAVY RAIN ALARM: rain rate is 100mm/h at 11:49 nov 09 2013".
Some idea about it?

Thanks again everybody!!! [tup]

Federico
Federico
Perugia, Italy


WCDev

  • WeatherCat Developer
  • Administrator
  • Storm
  • *****
  • Posts: 2911
    • CW9739
    • ISCOTLAN25
    • Trixology
  • Station Details: Main Station: Vantage Pro-2, 24hr fars, solar, soil/leaf station, extra temp stations, no U.V. WeatherLink IP.
Re: Problems with Scripts and Email to Twitter and Facebook
« Reply #1 on: November 08, 2013, 05:28:49 PM »
Hi Federico,
Maybe there's some setting on Facebook that filters the body of the email out?

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6494
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Might be easier to use AppleScript (Re: Problems with Scripts to Twitter)
« Reply #2 on: November 08, 2013, 10:53:40 PM »
Hi Federico and WeatherCat fans,

There was a script uploaded by a american member (Rick, GoldenGoose) that with Cronnix allowed to upload WeatherCat data (daily, weekly, monthly data, webcam images, statistics…etc) to Twitter. Now Twitter API version is uploaded to from 1 to 1.1 and it doesn't run since last june.
I've tried to update API, Python, Tweepy….but NO WAY ti upload data in that way.
I know there is another script (Thanks Eduard!) but with last method I was able to custom different scripts at different time to upload different data to Twitter.

I think you are going to have a very hard time trying to coax those old scripts to work again with Twitter.  The only reason my AppleScript is still working is because of the nice fellow at J. A. Computing who created a patched version of his own AppleScript libraries.  As far as I know, he - still - hasn't gotten all of this library's routines to work properly since the Twitter API upgrade.

Have you looked at my AppleScript at all?  If you had a version that just made a Twitter upload and quit would that work for you?  I'm up to neck in shakedown "issuez" related to (guess what) . . .    However, I might be able to put together a tweaked AppleScript that you could run using Cronnix.  You could have multiple versions of the same AppleScript with slilghtly different names and that might do what you want.

Cheers, Edouard  [cheers1]

meteoperugia

  • Gentle Breeze
  • **
  • Posts: 79
    • DW0950
    • IPERUG54
    • MeteoPerugia
  • Station Details: Davis Vantage Pro2, iMac (Retina 5K, 27-inch, Late 2015), WeatherCat 3
Re: Problems with Scripts and Email to Twitter and Facebook
« Reply #3 on: November 09, 2013, 04:26:25 PM »
Hi Stu!
No, all settings on Facebook and twitter are fine and if I post a message @Twitter after few seconds it will be repeated @FB. The problem is about permissions for post messages @ Twitter from third party program/script because API was been upgraded from ver 1 to 1.1 and procedure of authentication is different now.

About Facebook function "post from email" if you send an email message to a definite Facebook address it will be post in your FB page BUT NOT the body text of the message but just the TITLE so all my message alert from WeatherCat to FB address are just "HEAVY RAIN ALERT" or " ICY ALERT" (etc) WITHOUT weather data that are present on the text body.
I wondering if there is possibility to add even if just 1 weather data to the email object in order to see "HEAVY RAIN ALERT. RAIN RATE IS 100mm/h at [time and date]".

Hi Eduard,
I'm already using your script (working very well!) to send to Twitter a string with a summary of weather data every hour. I wish I could create different scripts with different strings based on webtags so I can send hourly data, daily data, weekly and monthly data, weather forecast, webcam image etc ... at times and dates scheduled (by Cronnix?).
Before I had 8 different scripts that regulated by Cronnix sent data to Twitter (which then sent them to Facebook) at intervals of 1 hour, 12 hours, 24 hours, 1 week and 1 month.....
This for example is the script that sent the monthly summary on the last day of each month

Quote
#!/usr/bin/python

import sys
import tweepy

CONSUMER_KEY = 'xxxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxxxxx'
USER_TOKEN = 'xxxxxxxxxxxxxxxxxxx'
USER_SECRET = 'xxxxxxxxxxxxxxxxxxxx'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(USER_TOKEN, USER_SECRET)
api = tweepy.API(auth)

statusUpdate = "Dati Mensili: MAX STAT$TEMPERATURE:MAX:THISMONTH$C il STAT$TEMPERATURE:MAX:THISMONTH:TIME$*MIN STAT$TEMPERATURE:MIN:THISMONTH$C il STAT$TEMPERATURE:MIN:THISMONTH:TIME$*Vento STAT$WINDSPEED:MAX:THISMONTH$ WINDSPEEDUNITS$ il STAT$WINDSPEED:MAX:THISMONTH:TIME$*Pioggia STAT$RAIN:TOTAL:THISMONTH$ RAINUNITS$"

statusdate = statusUpdate[140:]
api.update_status(statusUpdate)

Following script sent a webcam image to twitter (and Facebook later) at 7.00, 12.00 and 18.00…..

Quote
#!/usr/bin/python

import sys
import tweepy

CONSUMER_KEY = 'xxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxx'
USER_TOKEN = 'xxxxxxxxxxxxxxxxxxx'
USER_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(USER_TOKEN, USER_SECRET)
api = tweepy.API(auth)

statusUpdate = "http://www.meteoperugia.altervista.org/webcam800.jpg"

statusdate = statusUpdate[140:]
api.update_status(statusUpdate)

AppleScript you're talking about (the tweaked on!) will be exactly what I need! ;)
Think about your (fantastic) GhostBuster car and when you'll be free let me know if there are news about scripts. There is no hurry.

Thanks everybody guys. Glad to meet you again

I offer a pint of Imperial IPA to each of you. I brew it according to BrewDog Scottish recipe and I know you'd like it ..... although those of brewdog are honestly better than mine!
That's the label  [cheers1] [beer]
Federico
Perugia, Italy


meteoperugia

  • Gentle Breeze
  • **
  • Posts: 79
    • DW0950
    • IPERUG54
    • MeteoPerugia
  • Station Details: Davis Vantage Pro2, iMac (Retina 5K, 27-inch, Late 2015), WeatherCat 3
Re: Problems with Scripts and Email to Twitter and Facebook
« Reply #4 on: November 09, 2013, 04:40:18 PM »
[OT]About Brewdog IPA I'm sure Stu knows what I'm speaking about but for yankee Eduard is something like FlyingDog or DogFish beers…..but scottish
I'm brewing IPA and American Pale Ale which are my favorite beers and I am proud of my beers that are perhaps not as good as these but they are better than many others who are famous in stores. That's my last creatures……  [bounce]
[cheers1]





Sorry for the name of one of my beer that is a dirty word. I've removed…  ;)

[end of OT]
Federico
Perugia, Italy


WCDev

  • WeatherCat Developer
  • Administrator
  • Storm
  • *****
  • Posts: 2911
    • CW9739
    • ISCOTLAN25
    • Trixology
  • Station Details: Main Station: Vantage Pro-2, 24hr fars, solar, soil/leaf station, extra temp stations, no U.V. WeatherLink IP.
Re: Problems with Scripts and Email to Twitter and Facebook
« Reply #5 on: November 09, 2013, 07:55:08 PM »

About Facebook function "post from email" if you send an email message to a definite Facebook address it will be post in your FB page BUT NOT the body text of the message but just the TITLE so all my message alert from WeatherCat to FB address are just "HEAVY RAIN ALERT" or " ICY ALERT" (etc) WITHOUT weather data that are present on the text body.
I wondering if there is possibility to add even if just 1 weather data to the email object in order to see "HEAVY RAIN ALERT. RAIN RATE IS 100mm/h at [time and date]".

Ah, I see - I'll add it to the feature request list, thanks!

With regards to the removed content, personally I found it very funny, but you can't post it here :)

wurzelmac

  • Storm
  • *****
  • Posts: 1361
    • ITIROLPR2
    • Wetterstation Pr?graten am Gro?venediger
  • Station Details: Davis Vantage PRO2 Plus (24h fan aspirated, wireless) with UV/Solar | Weather Envoy Data Logger | Mac mini 2023 M2 8/256 | 1x Canon EOS 1300D | macOS Sonoma 14.2
Re: Problems with Scripts and Email to Twitter and Facebook
« Reply #6 on: November 09, 2013, 08:34:09 PM »
Thanks for removing - not funny for me.  :-X

Sorry for that, Federico. I will never understand, why words as used on your removed beer-label will ever be funny or cool.  :'(
No way.

Reinhard

Update: I don't know what a monkey has to do with Indians...  :-[
Reinhard


elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6494
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Can't grab webtags from AppleScript (Re: Problems with Scripts to Twitter)
« Reply #7 on: November 09, 2013, 10:17:38 PM »
Hi Federico and WeatherCat fans,

I'm already using your script (working very well!) to send to Twitter a string with a summary of weather data every hour. I wish I could create different scripts with different strings based on webtags so I can send hourly data, daily data, weekly and monthly data, weather forecast, webcam image etc ... at times and dates scheduled (by Cronnix?).

Hmm, what you are trying to do is more complex than an AppleScript can easily handle.  There is no way for an AppleScript to request things like webcam images or the weather forecast.  How were you doing this in the past?  Were you having WeatherCat creating special "web page" from a WeatherCat web template and then uploading that to Twitter?

Unfortunately, my Twitter AppleScript couldn't be used to do this even with a modification to run only once.  It might to be too hard to create an AppleScript that would read a web page file generated by WeatherCat and uploading it to Twitter using the J.A. Computing library.  Is that something that might work for you?

Cheers, Edouard  [cheers1]

meteoperugia

  • Gentle Breeze
  • **
  • Posts: 79
    • DW0950
    • IPERUG54
    • MeteoPerugia
  • Station Details: Davis Vantage Pro2, iMac (Retina 5K, 27-inch, Late 2015), WeatherCat 3
Re: Problems with Scripts and Email to Twitter and Facebook
« Reply #8 on: November 09, 2013, 10:58:46 PM »
Thanks for removing - not funny for me.  :-X

Sorry for that, Federico. I will never understand, why words as used on your removed beer-label will ever be funny or cool.  :'(
No way.

Reinhard

Update: I don't know what a monkey has to do with Indians...  :-[

Is just a beer I brew and store in my cellar and I drink with just 2-3 friends. You can listen the same word in thousand songs from the radio and hundreds movie from TV and your sons can do it too. It wouldn't be offensive (off course). It's an irreverent strong male American beer and that name it's a simple recall for anything above.
But I've removed.
Sorry again for mistake but if it's possible let's go ahead with the thread. Take it easy.  ;)

Update: the monkey is in all first beer label I've printed (as a brand). India Pale Ale is a style of British beer and not and Indian beer. It was a Pale Ale exported to India for British soldiers and because the journey with ships was very long it was brewed with more alcohol and more hops that are both natural preservative. Just last thing: India is FULL of monkeys but that's different matter.   [lol]
Federico
Perugia, Italy


meteoperugia

  • Gentle Breeze
  • **
  • Posts: 79
    • DW0950
    • IPERUG54
    • MeteoPerugia
  • Station Details: Davis Vantage Pro2, iMac (Retina 5K, 27-inch, Late 2015), WeatherCat 3
Re: Can't grab webtags from AppleScript (Re: Problems with Scripts to Twitter)
« Reply #9 on: November 09, 2013, 11:07:16 PM »
Hi Federico and WeatherCat fans,
Hmm, what you are trying to do is more complex than an AppleScript can easily handle.  There is no way for an AppleScript to request things like webcam images or the weather forecast.  How were you doing this in the past?  Were you having WeatherCat creating special "web page" from a WeatherCat web template and then uploading that to Twitter?

Unfortunately, my Twitter AppleScript couldn't be used to do this even with a modification to run only once.  It might to be too hard to create an AppleScript that would read a web page file generated by WeatherCat and uploading it to Twitter using the J.A. Computing library.  Is that something that might work for you?

Cheers, Edouard  [cheers1]

The script is simple as you can see. Maybe the problem is that uses WeatherCat web tags. All 8 scripts are similar and are in "source" WC folder. The specific string is different for each script and every time WC update weather conditions replaces web tags with new data and create a PHP script in "CUSTOM WEB" WC folder.
In attachment the read me file received from Rick (GoldenGoose) farmer member of this forum. I don't know so much about applescripts so I hope if you read the RTF it will be more clear what I'm talking about.
Many thanks in advance. [tup]
Federico
Perugia, Italy


elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6494
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Would need to save files and then Twit them. (Re: Webtags from AppleScript)
« Reply #10 on: November 10, 2013, 09:47:45 PM »
Hi Federico and WeatherCat fans,

The script is simple as you can see. Maybe the problem is that uses WeatherCat web tags. All 8 scripts are similar and are in "source" WC folder. The specific string is different for each script and every time WC update weather conditions replaces web tags with new data and create a PHP script in "CUSTOM WEB" WC folder.

Okay I see how this is supposed to work, but unfortunately, AppleScript isn't like PHP.  You can't use WeatherCat to process an AppleScript because WeatherCat won't recognize the file type.

The only way I can imagine doing this is to create a small file that has the text you want to have created.  Say in the example you post, create a WeatherCat template that just has this single line in it:

Code: [Select]
Temp: STAT$TEMPERATURE:CURRENT$ F * HeatIndex: STAT$HEATINDEX:CURRENT$ F * Hum: STAT$EXTHUMIDITY:CURRENT$% * Dew: STAT$DEWPOINT:CURRENT$ F * Baro: STAT$PRESSURE:CURRENT$ PRESSUREUNITS$ * UV: STAT$UV:CURRENT$ * Rain: STAT$RAIN:TOTAL:TODAY$ RAINUNITS$ @ t12$
This would create the line of text that you want posted to Twitter and save it as a text file.  An AppleScript could then open up this file and send the text within to Twitter.

Does that sound like something that would work for you?

Cheers, Edouard  [cheers1]

Steve

  • Global Moderator
  • Storm
  • *****
  • Posts: 1555
    • DW8454
    • KOHAVON11
    • Avon Weather
  • Station Details: Davis Wireless VP2 Plus w/24 hr FARS, Leaf & Soil Station, 2023 Mac mini M2 Pro, 32GB RAM, Mac OS 14, WeatherCat 3.2
Re: Might be easier to use AppleScript (Re: Problems with Scripts to Twitter)
« Reply #11 on: November 10, 2013, 09:53:08 PM »


Edouard and Federico,

I tried this method for doing a daily summary a year or so ago, and didn't get it to work. It was soon after you came up with the separate prefs file, so I copied the AppleScript and copied the prefs, renamed them, and changed internal pointers. I can't recall now why it didn't work. I vaguely recall that it had something to do with the o-auth or something, but I might be completely off. I might give this a go again and see.

Steve



You could have multiple versions of the same AppleScript with slilghtly different names and that might do what you want.
Steve - Avon, Ohio, USA


CWOP: DW8454 - WU: KOHAVON11 - AWEKAS - CoCoRaHS
PWSweather - WeatherCloud - Twitter - Facebook

meteoperugia

  • Gentle Breeze
  • **
  • Posts: 79
    • DW0950
    • IPERUG54
    • MeteoPerugia
  • Station Details: Davis Vantage Pro2, iMac (Retina 5K, 27-inch, Late 2015), WeatherCat 3
Re: Problems with Scripts and Email to Twitter and Facebook
« Reply #12 on: November 11, 2013, 11:16:15 AM »
The premise that I can do without all this, the PHP scripts that I mentioned were very comfortable because they can be easily customized by changing the entry of webtags of WeatherCat and schedulized with Cronnix. I tried to send a message to Rick to find out how I could make the scripts running again but still did not reply. Some appreciated read the forecast, weather data updates, webcam images, weather summaries... on Facebook at regular intervals and when the Twitter API 1.0 has stopped working I received several messages from people in the area that used to see every morning at the FB page local weather. So I tried to update the API and Python and Tweepy to new versions but it did not work anymore.
The best thing would be to have the ability to publish directly from WeatherCat on FaceBook text strings with WebTAG updated with weather data from WeatherCat and without going through Twitter and then without the limit of 140 digits ..... but I don't know if this is possible. Maybe a way could be using the Facebook "Email_upload" function, tweaking Wheatercat in order to upload data in the title of the messages….. maybe.  :)

At the moment I'm happy to send the weather updates every hour with Edouard script that works fine….  ;)

Thanks everybody for support  [tup]
Federico
Perugia, Italy


elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6494
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
It would be a new AppleScript. (Re: Problems with Scripts to Twitter)
« Reply #13 on: November 11, 2013, 07:35:36 PM »
Howdy Steve, Federico, and WeatherCat scripting tinkerers,

I tried this method for doing a daily summary a year or so ago, and didn't get it to work.

Actually, I was thinking about coming up with an entirely different AppleScript where the problem of preferences wouldn't come up.  All this AppleScript would do is read a file that WeatherCat had processed and upload the string to twitter verbatim.  Since it would be very short, I thought I would just have a single preference embedded in the file that would be easy to edit using the AppleScript editor.  In this scheme each additional twit would have a separate AppleScript application associated with it.  You would just edit the name of the file WeatherCat creates in each case.

I took a quick look at this stuff yesterday, but this morning I'm back to them other "issuez."  I'll try to take another look later on.  It doesn't look difficult, but I need a little free time to try it out.

Cheers, Edouard  [cheers1]

Steve

  • Global Moderator
  • Storm
  • *****
  • Posts: 1555
    • DW8454
    • KOHAVON11
    • Avon Weather
  • Station Details: Davis Wireless VP2 Plus w/24 hr FARS, Leaf & Soil Station, 2023 Mac mini M2 Pro, 32GB RAM, Mac OS 14, WeatherCat 3.2
Re: Problems with Scripts and Email to Twitter and Facebook
« Reply #14 on: November 12, 2013, 01:30:01 AM »
That sounds pretty interesting, Edouard! You need to duct tape the MPB to the dash of teh Buick so you can enjoy both hobbies at the same time! :)
Steve - Avon, Ohio, USA


CWOP: DW8454 - WU: KOHAVON11 - AWEKAS - CoCoRaHS
PWSweather - WeatherCloud - Twitter - Facebook