Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python the code strftime("%s") errors

Tags:

python

THE python program is as follows, it errors:

File "C:\Python\PyCharmProject\FaceBookCrawl\group_download.py", line 31, in getFeed params += "&since=" + SINCE.strftime("%s")
ValueError: Invalid format string

the program it seems SINCE.strftime("%s") is wrong, how to solve it?

SINCE = datetime.datetime.now() - datetime.timedelta(DAYS)

params = "?fields=permalink_url,from,story,type,message,link,created_time,updated_time,likes.limit(0).summary(total_count),comments.limit(0).summary(total_count)"

#Default paging limit
params += "&amp&limit=" + DEFAULT_LIMIT

#Time-based limit
params += "&since=" + SINCE.strftime("%s")
graph_url = GRAPH_URL_PREFIX + group + "/feed" + params
like image 301
bin Avatar asked Oct 17 '25 02:10

bin


1 Answers

For anybody coming here when using ("%s") to generate an Epoch timestamp. Note that the usage of strftime("%s") is platform dependent and doesnt work on windows while it works on Linux with you Local Timezone. You can just use timestamp():

int(datetime.datetime.utcnow().timestamp())

You can read more here Convert python datetime to epoch with strftime

like image 170
user16543787 Avatar answered Oct 18 '25 15:10

user16543787



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!