Page 1 of 1
Multiple conditional expressions for Twitter **solved**
Posted: Fri Oct 21, 2016 4:53 am
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"
Re: Multiple conditional expressions for Twitter
Posted: Mon Oct 24, 2016 6:29 pm
by admin
Re: Multiple conditional expressions for Twitter
Posted: Mon Oct 31, 2016 3:00 am
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
Re: Multiple conditional expressions for Twitter
Posted: Mon Oct 31, 2016 2:08 pm
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.
Re: Multiple conditional expressions for Twitter
Posted: Mon Oct 31, 2016 10:26 pm
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)
Re: Multiple conditional expressions for Twitter
Posted: Tue Nov 01, 2016 2:20 pm
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.
Re: Multiple conditional expressions for Twitter
Posted: Tue Nov 01, 2016 3:36 pm
by WA4OPQ
Success. Thank you!
I'll be busy creating descriptive tweets today.