Page 1 of 1

Tweepy/TwitterAPI

Posted: Sun Oct 07, 2018 11:34 am
by larsgimse
Hello
I am newbie with MicroPython an ESP8266/NodeMCU. I like to make and code IoT stuff talking with Twitter (https://twitter.com/talktomangotree and https://twitter.com/digi_plant)

One question.
It is possible to include libraries like TwitterAPI (https://github.com/geduldig/TwitterAPI), Tweepy (https://github.com/tweepy/tweepy) and Twython (https://github.com/ryanmcgrath/twython) on MicroPython?

I am running esp8266-20180511-v1.9.4.bin on my NodeMCU and WebREPL working fine. I have try different Python3 code.

If it possible, anyone can tell me how to do it?

Thanks

- Lars

Re: Tweepy/TwitterAPI

Posted: Sun Oct 07, 2018 6:12 pm
by jickster
I am not familiar with any ESP hardware.

On your ESP, do you have the ability to load a .py using sd card or by placing the .py onto the file system?


Sent from my iPhone using Tapatalk Pro

Re: Tweepy/TwitterAPI

Posted: Sun Oct 07, 2018 8:03 pm
by larsgimse
Yes I think so, with ampy or WebREPL

Re: Tweepy/TwitterAPI

Posted: Mon Oct 08, 2018 1:51 am
by larsks
larsgimse wrote:
Sun Oct 07, 2018 11:34 am
It is possible to include libraries like TwitterAPI (https://github.com/geduldig/TwitterAPI), Tweepy (https://github.com/tweepy/tweepy) and Twython (https://github.com/ryanmcgrath/twython) on MicroPython?
Generally, no, it's not. Those libraries were written for Python, but you're running MicroPython. While the core syntax is very similar, there are enough differences that any non-trivial code written for one will probably not run on the other. You'll want to look for libraries that have been explicitly written for MicroPython.

-- Another Lars

Re: Tweepy/TwitterAPI

Posted: Mon Oct 08, 2018 2:31 am
by jickster
larsgimse wrote:Yes I think so, with ampy or WebREPL
Load one of those .py files into your hw and try to import using REPL.


Sent from my iPhone using Tapatalk Pro

Re: Tweepy/TwitterAPI

Posted: Mon Oct 08, 2018 5:16 am
by SpotlightKid
You just have to look at the setup.py of one of these mentioned libs and notice their dependencies to realize that they won't work under MicroPython. As already said above, very few libs for CPython will work on MicroPython.

Re: Tweepy/TwitterAPI

Posted: Mon Oct 08, 2018 6:25 am
by larsgimse
Thanks for all the answers. That's what I thought it's not as easy with what is encoded in Python and use in MicroPython. I'm going to look for libraries customized to MicroPython. Are there any of you who have good examples of Twitter wrapping in MicroPython?

- Lars

Re: Tweepy/TwitterAPI

Posted: Mon Oct 08, 2018 7:26 pm
by larsks
I was going to suggest that you could just read through the Twitter API docs at https://developer.twitter.com/en/docs.html and then use something like the

Code: Select all

urequests
module, but it looks as if micropython implementation issues make this largely impossible.

Specifically, calling

Code: Select all

urequests.get
against the twitter search API (https://api.twitter.com/1.1/search/tweets.json) causes some sort of buffer overflow, regardless of whether or not ones tries to read the content. Without true support for a streaming API, the low memory of the esp8266 is going to throw a wrench into things.

I also looked at the

Code: Select all

urllib.urequest
module, but it doesn't appear to support things like custom http headers. I haven't looked at

Code: Select all

uaiohttpclient
.

Re: Tweepy/TwitterAPI

Posted: Tue Oct 09, 2018 6:56 am
by larsgimse
Thank you for your testing and good tips. As mentioned earlier, I'm very new to both Python and MicroPython. I find codes online and adapt them to my ideas, but it's exciting to learn Python and MicroPython.

Re: Tweepy/TwitterAPI

Posted: Wed Jul 27, 2022 10:33 pm
by gingerman
Hiya,

You could det up your twitter API using something like Php, Node etc or probably something like Firebase on a more capable computer like a Pi Zero, or on your private web server ( there are some for $2 / month ).

Then you could just connect to that web server from your Pico W and just add methods to send and retrieve data from your 'proper' server to and from your Pico W.

So you could keep the code to a minimum on the Pico W, and use the rest of it to react to or transmit data back to the server's live data.

eg you want to tweet the temperature every hour, so your Pico looks at the temperature and sends a simple request to your 'proper' server.
Your proper server then authenticates itself with Twitter ( or any service you can use an API with ), and it tweets the temperature.

Alternatively - your proper server 'sees' a like to your tweet and it sends a request back to your Pico W, and your Pico W reacts by twisting a servo motor, playing a sound and lighting up some addressable LEDs.

Or - your Pico W checks every 10 minutes for new events and sends the latest temperature at the same time ( or whatever you are doing ) and everything updates accordingly.

I've done a lot of API work with Twitter, Facebook, YouTube, etc ( its a whole lot of fun ).

PS People who answer 'I don't know, but can it do X," really annoy me :)
( NOT ALL QUESTIONS ARE MEANT FOR EVERYBODY - DON'T ANSWER EVERY QUESTION IF YOU DON'T KNOW SOMETHING OR DON'T HAVE SOMETHING TO OFFER ) - drives me mental :) lol :) All good - have a great day hacking.

Try a Linode free for a month server - something like that :)