Commit ddc9f2d2 authored by Francesco Poldi's avatar Francesco Poldi

Fixed timedelta

Added a mitigation because twitter does not work well with given "since" and "until" dates.

Example: https://twitter.com/search?f=tweets&vertical=default&l=de&lang=en&q=%20metoo%20since%3A2017-12-01%20until%3A2017-12-02
this returns tweets until 2017-11-30 which is not good
parent 9175457b
...@@ -302,6 +302,9 @@ async def outTweet(tweet): ...@@ -302,6 +302,9 @@ async def outTweet(tweet):
datestamp = tweet.find("a", "tweet-timestamp")["title"].rpartition(" - ")[-1] datestamp = tweet.find("a", "tweet-timestamp")["title"].rpartition(" - ")[-1]
d = datetime.datetime.strptime(datestamp, "%d %b %Y") d = datetime.datetime.strptime(datestamp, "%d %b %Y")
date = d.strftime("%Y-%m-%d") date = d.strftime("%Y-%m-%d")
if (d.date() - datetime.datetime.strptime(arg.since, "%Y-%m-%d").date()).days == -1:
# mitigation here, maybe find something better
sys.exit(0)
timestamp = str(datetime.timedelta(seconds=int(tweet.find("span", "_timestamp")["data-time"]))).rpartition(", ")[-1] timestamp = str(datetime.timedelta(seconds=int(tweet.find("span", "_timestamp")["data-time"]))).rpartition(", ")[-1]
t = datetime.datetime.strptime(timestamp, "%H:%M:%S") t = datetime.datetime.strptime(timestamp, "%H:%M:%S")
time = t.strftime("%H:%M:%S") time = t.strftime("%H:%M:%S")
...@@ -629,7 +632,10 @@ async def main(): ...@@ -629,7 +632,10 @@ async def main():
sys.exit(1) sys.exit(1)
if not arg.timedelta: if not arg.timedelta:
arg.timedelta = 30 if (_until - _since).days > 30:
arg.timedelta = 30
else:
arg.timedelta = (_until - _since).days
if arg.userid is not None: if arg.userid is not None:
arg.u = await getUsername() arg.u = await getUsername()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment