You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/code-snippets.md
+12-34
Original file line number
Diff line number
Diff line change
@@ -866,7 +866,6 @@ Below is how to a reply chain aka threaded tweets. This will make an initial twe
866
866
867
867
!>**Untested code**- it might be better to reply to the initial ID only.
868
868
869
-
870
869
```python
871
870
screen_name= api.me().screen_name
872
871
@@ -879,7 +878,7 @@ target_id = None
879
878
880
879
for message in messages:
881
880
if target_id isNone:
882
-
print("Initital tweet!")
881
+
print("Initial tweet!")
883
882
else:
884
883
print(f"Replying to tweet ID: {target_id}")
885
884
message=f"@{screen_name}{message}"
@@ -895,50 +894,29 @@ for message in messages:
895
894
## Handle time values
896
895
> Tips on dealing with time values from the Twitter API
897
896
898
-
### Date and time
899
-
900
-
The Twitter API often provides a datetime value in [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) formatand Tweepy returns this to you as a string still.
901
-
902
-
e.g. `"2020-05-03T18:01:41+00:00"`.
903
-
904
-
This section covers how to parse a datetime string to a timezone-aware datetime object, to make it more useful for calculations and representations.
905
-
906
-
```python
907
-
import datetime
908
-
897
+
See also my [Time handling](https://michaelcurrin.github.io/dev-cheatsheets/cheatsheets/python/time-handling.html) Python cheatsheet.
909
898
910
-
TIME_FORMAT_IN=r"%Y-%m-%dT%H:%M%z"
911
-
912
-
913
-
def parse_datetime(value):
914
-
"""
915
-
Convert from Twitter datetime string to a datetime object.
The Twitter API often provides a datetime value in [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) formatand Tweepy returns this to you as a string.
926
902
927
-
?> When splitting, we don't need seconds and any decimals values. Plus, these have changed style before between API versions so are unreliable. So we just ignore after the 2nd colon (minutes) and pick up the timezone from the last 6 characters.
903
+
e.g. `"2020-01-24T12:34:56+00:00"`.
928
904
929
905
?> The datetime value from Twitter will be always be UTC zone (GMT+00:00), regardless of your location or profile settings. Lookup the datetime docs for more info.
930
906
931
-
Example usage:
907
+
Convert to a timezone-aware datetime object, to make it more useful for calculations and representations:
0 commit comments