Tweepy/TwitterAPI

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
larsgimse
Posts: 4
Joined: Sun Oct 07, 2018 11:25 am

Tweepy/TwitterAPI

Post by larsgimse » Sun Oct 07, 2018 11:34 am

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

jickster
Posts: 546
Joined: Thu Sep 07, 2017 8:57 pm

Re: Tweepy/TwitterAPI

Post by jickster » Sun Oct 07, 2018 6:12 pm

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

larsgimse
Posts: 4
Joined: Sun Oct 07, 2018 11:25 am

Re: Tweepy/TwitterAPI

Post by larsgimse » Sun Oct 07, 2018 8:03 pm

Yes I think so, with ampy or WebREPL

larsks
Posts: 15
Joined: Mon Feb 13, 2017 5:27 pm

Re: Tweepy/TwitterAPI

Post by larsks » Mon Oct 08, 2018 1:51 am

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

jickster
Posts: 546
Joined: Thu Sep 07, 2017 8:57 pm

Re: Tweepy/TwitterAPI

Post by jickster » Mon Oct 08, 2018 2:31 am

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

SpotlightKid
Posts: 377
Joined: Wed Apr 08, 2015 5:19 am

Re: Tweepy/TwitterAPI

Post by SpotlightKid » Mon Oct 08, 2018 5:16 am

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.

larsgimse
Posts: 4
Joined: Sun Oct 07, 2018 11:25 am

Re: Tweepy/TwitterAPI

Post by larsgimse » Mon Oct 08, 2018 6:25 am

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

larsks
Posts: 15
Joined: Mon Feb 13, 2017 5:27 pm

Re: Tweepy/TwitterAPI

Post by larsks » Mon Oct 08, 2018 7:26 pm

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
.

larsgimse
Posts: 4
Joined: Sun Oct 07, 2018 11:25 am

Re: Tweepy/TwitterAPI

Post by larsgimse » Tue Oct 09, 2018 6:56 am

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.

Post Reply