If condition doesn't trigger - twitter

Long story short story, I am playing with the tweepy library to make a markov bot on twitter: I am now trying to answer to the right tweet but...
>>> repr(mention.id)
'698147667990441984'
>>> repr(698147667990441984)
'698147667990441984'
>>> mention.id is 698147667990441984
False
>>>
The ID of the targeted tweet (I am currently working with a hardcoded tweet) has this exact ID but for some reason any check leads to a 'False' no matter how I do it (for instance by trying to convert it into strings)
Thanks in advance

The tweet ID is most probably a string. So just put it between quotation marks: mention.id is '698147667990441984'

Related

GSheets - How to query a partial string

I am currently using this formula to get all the data from everyone whose first name is "Peter", but my problem is that if someone is called "Simon Peter" this data is gonna show up on the formula output.
=QUERY('Data'!1:1000,"select * where B contains 'Peter'")
I know that for the other formulas if I add an * to the String this issue is resolved. But in this situation for the QUERY formula the same logic do not applies.
Do someone knows the correct syntax or a workaround?
How about classic SQL syntax
=QUERY('Data'!1:1000,"select * where B like 'Peter %'")
The LIKE keyword allows use of wildcard % to represent characters relative to the known parts of the searched string.
See the query reference: developers.google.com/chart/interactive/docs/querylanguage You could split firstname and lastname into separate columns, then only search for firstnames exactly equal to 'Peter'. Though you may want to also check if lowercase/uppercase where lower(B) contains 'peter' or whitespaces are present in unexpected places (e.g., trim()). You could also search only for values that start with Peter by using starts with instead of contains, or a regular expression using matches. – Brian D
It seems that for my case using 'starts with' is a perfect fit. Thank you!

Problems with a include or if in rails

Im having issues with rails with the code
if #turno.chop == res[:department].to_s
where turno contains strings like ABC1 and department like ABC, im trying to filter if turno its equal of department but i need reduce the string of turno for that.
Every time what i try to do that the code dont finish and stuck in other part of code, when i delete the condition, the code works perfectly but dont do the filter.
i tryid to to do like
if #turno.include?(res[:department].to_s)
But appears the same error.
I believe something very similar to this was answered in the stackoverflow.com question. How to check whether a string contains a substring in Ruby?
The include? command sounds like what you should use.
my_string = "abcdefg"
if my_string.include? "cde"
puts "String includes 'cde'"
end
To be more accurate, #turno can contain a string like "ABC1" and res[:department] contains a string with "ABC" i need reduce the string in #turno to the first X characters and compare it with the content of res[:department]

Rails Regex Match Group Overwriting itself

I am trying to match this string:
NFPA 101 19.7.2.2
and am using this regex:
(NFPA) (\w+)(?: ?(?:([^.]+)\.?)+)?
This seems to match the string, but the captured groups are not what I'm looking for. I expect:
NFPA
101
19
7
2
2
What I get is this:
NFPA
101
2
See this rubular example:
http://rubular.com/r/43VY0yyNa7
It's as if that last recurring capture group is being overwritten by the final match. Is there a way to have all of these come back as capture groups as I need?
Added another regex that gives me the similar problem described above:
(NFPA) (.+) (.+?.)+(.+)
The issue is you're using non-capturing group symbol : which isn't gonna work to select the string as separate capture group. To overcome the issue you need to use Positive / Negative Lookahead. So, the following regex should work in this case :
(\w+|\d+[-]\d+)(?=\s?)(?![-])
see demo

XNA Keys number 1

I need to ask when the number 1 key is pressed, NOT on the Numpad, but the number 1 that is over the Q (trying to make this as clear as possible).
I've been through all the available keys on the Keys array, but no one matches the one that I am looking for.
Is there a way to do this that I'm missing?
My code:
If (currentKeyboardState.IsKeyDown(Keys.1))
Should be the Keys.D1 key. The number keys are D0-D9. The documentation is here.
The documentation says: Used for miscellaneous characters; it can vary by keyboard.
To clarify: Keys.D1 works (e.g. Keys.D[insert number here]).
if (keyState.IsKeyDown(Keys.D4))
{
Console.WriteLine("You pressed the 4 key above E and R!");
}

How to identify a country from a normalized phone number?

I have a list of international phone numbers and a List of Country calling codes.
I would like to identify the Country from the numbers but I can't find a fast and elegant way to do it.
Any idea? The only I got is to have an hardcoded check (Eg. "look at the first number, look at the second number: if it's X then check for the third number. If the second number is Y then the Country is Foo", etc.).
I'm using PHP and a DB (MySQL) for the lists, but I think that any pseudocode will help.
Alternatively, you could use a tool like Twilio Lookup.
The CountryCode property is always returned when you make an API request with Lookup.
https://www.twilio.com/docs/api/lookups#lookups-instance-properties
[Disclosure: I work for Twilio]
i was after something similar to this, but i also wanted to determine the region/state - if available. in the end i hacked up something based on a tree of the digits leading digits (spurred on by the description at wikipedia)
my implementation is available as a gist.
I'm currently using an implementation of Google's libphonenumber in Node, which works fairly well. I suppose you could try a PHP implementation, e.g. libphonenumber-for-php.
The hard-coded check can be turned into a decision tree generated automatically from the list of calling codes. Each node of the tree defines the 'current' character, the list of possible following characters (tree nodes) or a country in case it's a terminal node. The root node will be for the leading '+' sign.
The challenge here is that some countries share the same phone country code. E.g. both Canada and the US have phone numbers starting with +1.
I'm using https://github.com/giggsey/libphonenumber-for-php as following:
/**
* Get country
* #param string $phone
* #param string $defaultCountry
* #return string Country code, e.g. 'CA', 'US', 'DE', ...
*/
public static function getCountry($phone, $defaultCountry) {
try {
$PhoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$PhoneNumber = $PhoneNumberUtil->parse($phone, $defaultCountry);
$country = $PhoneNumberUtil->getRegionCodeForNumber($PhoneNumber);
return $country;
} catch (\libphonenumber\NumberParseException $e) {
}
return $defaultCountry;
}
You can easily do a simple lookup starting with the first number, then the second, and so on until you find it. This will work correctly because no calling code is a prefix of another code, i.e. the international calling codes form a "prefix code" (the phone system relies on this property).
I'm not good any good at PHP so here is a simple python implementation; hopefully it is easy to follow:
>>> phone_numbers = ["+12345", "+23456", "+34567", "+45678"]
>>> country_codes = { "+1": "USA", "+234": "Nigeria", "+34" : "Spain" }
>>> for number in phone_numbers:
... for i in [2, 3, 4]:
... if number[:i] in country_codes:
... print country_codes[number[:i]]
... break
... else:
... print "Unknown"
...
USA
Nigeria
Spain
Unknown
Essentially you have an associative array between prefixes and countries (which I assume you can easily generate from that Wikipedia article. You try looking up the first digit of the phone number in the associative array. If it's not in the array you try the first two digits, then the first three. If there is no match after three digits then this number doesn't start with a valid international calling code.

Resources