Multiple conditional expressions for Twitter **solved**

All about the standard Meteobridge devices based on mobile routers from TP-Link, D-Link, ASUS

Moderator: Mattk

Post Reply
User avatar
WA4OPQ
Senior Boarder
Senior Boarder
Posts: 44
Joined: Mon Feb 29, 2016 5:36 am
Location: Tennessee, USA About 40 miles west of Nashville y'all.
Contact:

Multiple conditional expressions for Twitter **solved**

Post by WA4OPQ »

Is it possible to have multiple conditional expressions to modify the wording of a tweet?
Here's a rough example:
If temp>40F & temp<50F then "It's cold"
If temp>32F & temp<40 then "It's very cold"
If temp<32F then "It's freezing cold"
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7874
Joined: Mon Oct 01, 2007 10:51 pm

Re: Multiple conditional expressions for Twitter

Post by admin »

User avatar
WA4OPQ
Senior Boarder
Senior Boarder
Posts: 44
Joined: Mon Feb 29, 2016 5:36 am
Location: Tennessee, USA About 40 miles west of Nashville y'all.
Contact:

Re: Multiple conditional expressions for Twitter

Post by WA4OPQ »

So, if multiple conditional expressions are allowed, I should be able to have a statement that changes:
It is cool outside
It is cold outside
It is freezing outside

But I'm stuck if an else statement is required.

It is #if# {[th0temp-act=F.1:0] < 45} & {[th0temp-act=F.1:0] > 40} #then# cool #if# {[th0temp-act=F.1:0] < 40} & {[th0temp-act=F.1:0] > 32} #then# cold #if# {[th0temp-act=F.1:0] < 32} & {[th0temp-act=F.1:0] > 20} #then# freezing outside

or should it be

It is #if# {[th0temp-act=F.1:0] < 45} & {[th0temp-act=F.1:0] > 40} #then# cool #else##fi# #if# {[th0temp-act=F.1:0] < 40} & {[th0temp-act=F.1:0] > 32} #then# cold #else##fi# #if# {[th0temp-act=F.1:0] < 32} & {[th0temp-act=F.1:0] > 20} #then# freezing #else##fi# outside
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7874
Joined: Mon Oct 01, 2007 10:51 pm

Re: Multiple conditional expressions for Twitter

Post by admin »

Please use round brackets "(", ")" to group arithmetic expressions.

"if-then-else-fi" clauses cannot be nested, so the second alternative looks better to me.
User avatar
WA4OPQ
Senior Boarder
Senior Boarder
Posts: 44
Joined: Mon Feb 29, 2016 5:36 am
Location: Tennessee, USA About 40 miles west of Nashville y'all.
Contact:

Re: Multiple conditional expressions for Twitter

Post by WA4OPQ »

Today is unseasonably warm so I did some experimenting. Here is my twitter string:

It is #if# ([th0temp-act=F.1:0] < 80) & ([th0temp-act=F.1:0] > 75) #then# very #else##fi# #if# ([th0temp-act=F.1:0] < 85) & ([th0temp-act=F.1:0] > 80) #then# pretty #else##fi# #if# ([th0temp-act=F.1:0] < 90) & ([th0temp-act=F.1:0] > 85) #then# pretty darned #else##fi# warm outside.

I received this result:
Error: sh: closing paren expected sh: closing paren expected can not post tweet (duplicate) (no more tries)
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7874
Joined: Mon Oct 01, 2007 10:51 pm

Re: Multiple conditional expressions for Twitter

Post by admin »

Ah, silly me! In order to evaluate the conditional clause (and not just to take it as a string) ist must be enclosed by "{*" and "*}".
Your text should look like this:

It is #if#{*([th0temp-act=F.1:0] < 80) & ([th0temp-act=F.1:0] > 75)*}#then# very #else##fi# #if#{*([th0temp-act=F.1:0] < 85) & ([th0temp-act=F.1:0] > 80)*}#then# pretty #else##fi# #if#{*([th0temp-act=F.1:0] < 90) & ([th0temp-act=F.1:0] > 85)*}#then# pretty darned #else##fi# warm outside.

Please give it a try.
User avatar
WA4OPQ
Senior Boarder
Senior Boarder
Posts: 44
Joined: Mon Feb 29, 2016 5:36 am
Location: Tennessee, USA About 40 miles west of Nashville y'all.
Contact:

Re: Multiple conditional expressions for Twitter

Post by WA4OPQ »

Success. Thank you!

I'll be busy creating descriptive tweets today.
Post Reply