Author Topic: TweetWX issue  (Read 2163 times)

0 Members and 1 Guest are viewing this topic.

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
TweetWX issue
« on: July 16, 2015, 07:13:59 PM »
After all the changes done to the NWS forecast over the last few weeks it now seems to be an issue for TweetWX. Twitter has a posting limit of 140 characters and before I had no issues until the recent changes is there anyway around this??

http://gosportwx.com/TweetWX/TweetWX-forecast.php
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline rrrick8

  • Senior Contributor
  • ****
  • Posts: 224
    • Vermilion weather
Re: TweetWX issue
« Reply #1 on: July 16, 2015, 08:45:18 PM »
You probably need to do what I did and put in a few more "$message = preg_replace"  in the script.

Find the section near the bottom of the script that looks like this...
Code: [Select]
$message = preg_replace('|this afternoon|i','Aft.noon',$message);
// $message = preg_replace('| night|is',' nite',$message);
$message = preg_replace('|chance|is','Chc',$message);
$message = preg_replace('|Partly|is','Ptly',$message);

then add a few more that may be hanging you up. Here is some of mine...
Code: [Select]
$message = preg_replace('|this afternoon|i','Aft.noon',$message);
$message = preg_replace('| night|is',' nite',$message);
$message = preg_replace('|chance|is','Chc',$message);
$message = preg_replace('|Partly|is','Ptly',$message);
$message = preg_replace('|showers|is','Shwrs',$message);
$message = preg_replace('|Mostly|is','Mstly',$message);
$message = preg_replace('|Scattered|is','Sctd',$message);
$message = preg_replace('|increasing|is','Incr.',$message);
        $message = preg_replace('|Cloudy|is','Cldy',$message);
        $message = preg_replace('|Thunder storm|is','Tstm',$message);
        $message = preg_replace('|Isolated|is','Iso',$message);
        $message = preg_replace('|T-Storms|is','Tstm',$message);

Make a copy of your original first in case you make an error.
« Last Edit: July 17, 2015, 08:18:02 AM by rrrick8 »
Severe Weather Manager-Vermilion County EMA
CWOP-CW9931 KILDANVI5

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9244
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: TweetWX issue
« Reply #2 on: July 17, 2015, 02:53:43 PM »
Yes, the new Dual Image forecasts can be quite verbose.  I've re-done TweetWX-forecast.php to V2.00

The new version has two main improvements:
1) a new method to specify shortening of the tweet words/terms
2) a fallback to make three tweets (one for each of the first 3 periods)

Hopefully, that will handle the new verbosity of the NWS forecasts :)

Just remember to update the attached with your auth info, and change the $tweetTags for your site.

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline W7RSW

  • Member
  • *
  • Posts: 15
    • WhitsWeb Weather
Re: TweetWX issue
« Reply #3 on: January 20, 2017, 07:03:31 PM »
Yes, the new Dual Image forecasts can be quite verbose.  I've re-done TweetWX-forecast.php to V2.00

The new version has two main improvements:
1) a new method to specify shortening of the tweet words/terms
2) a fallback to make three tweets (one for each of the first 3 periods)

Hopefully, that will handle the new verbosity of the NWS forecasts :)

Just remember to update the attached with your auth info, and change the $tweetTags for your site.

Best regards,
Ken

Thank you Ken, I've been trying to solve the problem of the character count your updated script addressed for hours.

The forecast script is working great except for one slight problem.

The output following includes a special HTML character that does not display properly:

NWS Fcst(3/3): Saturday: Snow Likely then Chance Snow, Hi 35F⇓;

It's supposed to display a down arrow or if &uArr is displayed, an up arrow show display.

All I ever see is the code, never the respective arrow. Is there somewhere I can change or delete the code for the character?


Otherwise, the changes you made work great. Thanks for solving the problem.

Regards,
Randy Whitney
W7RSW


Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9244
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: TweetWX issue
« Reply #4 on: January 20, 2017, 08:08:14 PM »
You can remove the up/down arrows by changing
Code: [Select]
$message = $tweetHeader . ' '. $fcst[0] . $fcst[1] . $fcst[2] . ' ' . $tweetTags;
if (strlen($message) > 135) {
to
Code: [Select]
$message = $tweetHeader . ' '. $fcst[0] . $fcst[1] . $fcst[2] . ' ' . $tweetTags;
$message = str_replace('⇓','',$message);
$message = str_replace('⇑','',$message);
if (strlen($message) > 135) {
and that should remove the pesky up/down arrow HTML entities from the text (and cut the character count).
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline W7RSW

  • Member
  • *
  • Posts: 15
    • WhitsWeb Weather
Re: TweetWX issue
« Reply #5 on: January 20, 2017, 09:01:55 PM »
That did it Ken!

No more of those pesky non-arrows and as you mentioned, decreased the character count below the 140 limit, allowing for a single tweet.

Thanks so much, I never would have figured out the necessary changes to the script. Maybe ten years ago, but past sixty and Alzheimers making an appearance have dimmed my abilities.

Thanks again and best regards.   :grin:
Randy Whitney
W7RSW


Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9244
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: TweetWX issue
« Reply #6 on: November 10, 2017, 05:23:25 PM »
I've found a better solution -- one that shows the up/down arrows in the tweets

There are two places in TweetWX-forecast.php that have
Code: [Select]
$utfmessage = iconv('ISO-8859-1','UTF-8//TRANSLIT',$message);
echo "UTF='$utfmessage' len=".strlen($utfmessage)." bytes.\nstatus=";

Change both of them to
Code: [Select]
$utfmessage = iconv('ISO-8859-1','UTF-8//TRANSLIT',$message);
$utfmessage = html_entity_decode($utfmessage,ENT_NOQUOTES | ENT_HTML5,'UTF-8');
echo "UTF='$utfmessage' len=".strlen($utfmessage)." bytes.\nstatus=";


That should replace the ↓ with a down arrow and ↑ with an up arrow in UTF-8 characters.

Note: I did update mine with the above change and it works
https://twitter.com/saratogaWX/status/929110072864669696

Note that if you made the above mod and had added
Code: [Select]
$message = str_replace('⇓','',$message);
$message = str_replace('⇑','',$message);
to your script, then delete those lines so the arrows will be converted to UTF-8 from HTML entities with the code in this post.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline rrrick8

  • Senior Contributor
  • ****
  • Posts: 224
    • Vermilion weather
Re: TweetWX issue
« Reply #7 on: November 10, 2017, 05:34:29 PM »
Instead of starting a new topic... I'll just use this one, Ken, what do you think about taking most of the abbreviated words out since Twitter is expanding to 280 characters now? 
Severe Weather Manager-Vermilion County EMA
CWOP-CW9931 KILDANVI5

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9244
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: TweetWX issue
« Reply #8 on: November 10, 2017, 10:10:16 PM »
You can give it a try.  I'm not sure all accounts on twitter have 280 chars now.

The code has three comparisons like strlen($message) > 135 in it .. change the 135 to 275 and see how that works.

I did the change on mine, and did a 154 character tweet, so I guess it works ok :)

« Last Edit: November 10, 2017, 10:16:19 PM by saratogaWX »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Gonzo1982

  • Member
  • *
  • Posts: 8
Re: TweetWX issue
« Reply #9 on: May 02, 2018, 02:27:21 PM »
What do the arrows signify?  Is the High up or down from the previous day or since the last update?

I've found a better solution -- one that shows the up/down arrows in the tweets

There are two places in TweetWX-forecast.php that have
Code: [Select]
$utfmessage = iconv('ISO-8859-1','UTF-8//TRANSLIT',$message);
echo "UTF='$utfmessage' len=".strlen($utfmessage)." bytes.\nstatus=";

Change both of them to
Code: [Select]
$utfmessage = iconv('ISO-8859-1','UTF-8//TRANSLIT',$message);
$utfmessage = html_entity_decode($utfmessage,ENT_NOQUOTES | ENT_HTML5,'UTF-8');
echo "UTF='$utfmessage' len=".strlen($utfmessage)." bytes.\nstatus=";


That should replace the ↓ with a down arrow and ↑ with an up arrow in UTF-8 characters.

Note: I did update mine with the above change and it works
https://twitter.com/saratogaWX/status/929110072864669696

Note that if you made the above mod and had added
Code: [Select]
$message = str_replace('⇓','',$message);
$message = str_replace('⇑','',$message);
to your script, then delete those lines so the arrows will be converted to UTF-8 from HTML entities with the code in this post.

 

anything