Thursday, October 27, 2016

Favorite Python Packages 01 - Making a chatbot

I had to write a logging handler for work that pushed errors up to HipChat. Turns out the process was so easy, I could not resist adding a chat-handler to ProsperCommon (esp given my hacky email handler). Despite my love for Slack, Discord became the tool-of-choice because it’s easy to stand-up/tear-down chats with a lot of flexibility. I also skipped Slack for now because the tweetfleet server blows past the 10k message buffer on a daily basis.

So, let's cook up a chatbot! Discord's API offerings are dizzying; this should be easy!

Discord.py - Making Chatbots Easy

Since Discord relies on an oAuth2 connection, and chats are inherently asynchronous, cooking up a bot from scratch would hurt. Discord.py to the rescue! This library has exceptional API coverage and is easy to use.

My one gripe is the documentation. Docs are sparse in places, but I'll forgive that sin with their example code and an active community on the Discord API Guild. Also, I had some trouble getting off the ground with the Discord API docs. Specifically, getting the correct tokens required to work, but once the bot was authenticated, it was off to the races!


TinyDB - The Easy Object-store

Pinging the internet for data is not free; whether because of rate limits or round trip times. Tools like SQLite are great for lightweight/portable data storage, but also requires schema design. MongoDB is a powerful noSQL solution, but is heavy to stand up (and I'm not in love with the query language). TinyDB comes to the rescue as a way to get the JSON/noSQL storage of MongoDB with none of the server/auth standup.

This shines when paired with REST endpoints. It's easy to push/pop entries around and keep the same raw JSON in archive as what's coming from the endpoint. Also, it's as easy as JSON to add more keys for searching. I'm still not in love with my cache-timer implementation in ProsperBot, but fetching from cache is 100x faster than an internet-call. Lastly, debug is easy since output is raw JSON, though this could lead to compression issues down the line.


Quick pro-tip about TinyDB: get ujson. This pure-C implementation of the JSON library is a great drop-in replacement. It can also be baked into libraries like Requests. ujson makes handling JSON lightning fast! Also, TinyDB has a wide array of extensions, and I will be looking into MongoDB hooks at a future date.

NLTK - Processing Text Made Easy

The number one problem I have with stock quotes: it takes 2-3 extra clicks to figure out WHY the price moved for the day. Google/Yahoo/etc provide great single-stock pages that give news summaries, but when you open a ticker or phone widget, only the raw numbers are reported. If I'm going to make a quote bot, why not include some information and save people a search?

The good news, Google/Yahoo both give a by-ticker API of relevant news articles. The bad news, they yield 10-15 articles in the query. Furthermore, the data isn't particularly ranked/scored from the source. I could have gambled with first-article being the best, or stacked a publisher priority order, but all I wanted was:
Good news when the stock is up.  Bad news when the stock is down
NLTK to the rescue. I have wanted to try my hand at sentiment/language analysis since I saw a local talk on Analyzing P2P Lending Data. Putting headlines through the vader_lexicon tools did exactly what I wanted and was blazing fast.

After playing with this quick demo of NLTK, I'm excited to expand this toolset.  If I can find the time, I'd very much like to write up a new discord bot for grading a community and highlighting troublemakers statistically rather than bluntly using block lists and word black-lists.

Let's See It!


I'm going to save the "how to get [stock] data" question for another blog.  There's a wide world of API's and support out there, and digging into them is worth a whole blog.  For the impatient, I used these two articles as a springboard to get started:
Though designing the bot language may require some creative design for EVE topics, standing up the bot should be easy.  I've been able to add functions at a uniquely fast pace (0.5-1d/feature) and standing up the whole bot took just a few evenings once I got through the roadblocks.  The libraries above are excellent tools to have in your tool box, and I'm excited to dig deeper into their functionality beyond the small `hello world` functions written so far!

39 comments:

Marti said...

EvE Online PLEX are additionally used to buy things in New Eden Store, for example, Skill Extractors, Multiple Pilot Training endorsements, garments, deliver skins and that's just the beginning. Much the same as if there should arise an occurrence of Omega Time, all things in the store can be purchased as a blessing as long as you have enough EVE PLEX put away in the PLEX vault.

madhudigitalmarketing said...

Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles Python Programming Training

Wajid Iquebal said...

Hi! This is my first comment here so I just wanted to give a quick shout out and say I genuinely enjoy reading your blog posts. Can you recommend any other Beauty Guest Post blogs that go over the same topics? Thanks a ton!

Unknown said...

Hello, Everyone,I'm Adrik Vadim living in Kurgan City , I want to share with you all on here on how Mr Benjamin help me with a loan of 15,000.000.00 Rubles to start up my food beverage delivery after all I have work in several hotels here in kurgan just to earn a living but unfortunate I was still having difficulties to pay a rent but I thank God now that I'm a self employ now with 5 workers working in my care. Just if you looking for financial freedom I will advise you contact Mr Benjamin with this email below and whats app number as well. 247officedept@gmail.com   +1-989-394-3740

Cyber Security Course said...

Writing in style and getting good compliments on the article is hard enough, to be honest, but you did it so calmly and with such a great feeling and got the job done. This item is owned with style and I give it a nice compliment. Better!
Cyber Security Training in Bangalore

Data Science Training said...

Really nice and interesting blog information shared was valuable and enjoyed reading this one. Keep posting. Thanks for sharing.
Data Science Training in Hyderabad

Institute Programs said...


Really, this article is truly one of the best, information shared was valuable and resourceful Very good work thank you.
Data Scientist Training in Hyderabad

Unknown said...

Hi friends i just want to use this opportunity to thank this great loan officer Mr Ben Lee who helped me with a loan i was very in need of $7,000,000.00 USD so i was introduce to Mr Ben Lee a loan officer so i contacted his email and i got the loan amount of $7,000,000.00 USD  i will advice anyone who is in need of a loan to contact email: 247officedept@gmail.com Or you can whatsapp his via  +1-989-394-3740.

eloisesmith said...


If you need a cheap and reliable EVE Echoes ISK, you can log in to the MMOWTS website to purchase.

eloisesmith said...

When players are in the Eve game, they need EVE Echoes ISK. So MMOWTS exists as a website that helps them a lot.

Mallela said...

Thanks for posting the best information and the blog is very informative.Data science course in Faridabad

360digiTMG Training said...


Very awesome!!! When I searched for this I found this website at the top of all blogs in search engines.

Best Institute for Data Science in Hyderabad

traininginstitute said...

This post is very simple to read and appreciate without leaving any details out. Great work!
best data science institute in hyderabad

Mallela said...

Thanks for posting the best information and the blog is very important.data science institutes in hyderabad

traininginstitute said...

This post is very simple to read and appreciate without leaving any details out. Great work!
business analytics course

Deekshitha said...

Informative blog
data analytics courses in hyderabad

Deekshitha said...

Informative blog
data analytics courses in hyderabad

Gamze said...

adana escort - adıyaman escort - afyon escort - aksaray escort - antalya escort - aydın escort - balıkesir escort - batman escort - bitlis escort - burdur escort - bursa escort - diyarbakır escort - edirne escort - erzurum escort - eskişehir escort - eskişehir escort - eskişehir escort - eskişehir escort - gaziantep escort - gebze escort - giresun escort - hatay escort - ısparta escort - karabük escort - kastamonu escort - kayseri escort - kilis escort - kocaeli escort - konya escort - kütahya escort - malatya escort - manisa escort - maraş escort - mardin escort - mersin escort - muğla escort - niğde escort - ordu escort - osmaniye escort - sakarya escort - samsun escort - siirt escort - sincan escort - tekirdağ escort - tokat escort - uşak escort - van escort - yalova escort - yozgat escort - urfa escort - zonguldak escort

Unknown said...

Fantastic article I ought to say and thanks to the info. Instruction is absolutely a sticky topic. But remains one of the top issues of the time. I love your article and look forward to more.
Data Science Course in Bangalore

DataScienceEXPO said...

Thank you quite much for discussing this type of helpful informative article. Will certainly stored and reevaluate your Website.
Data Analytics Course in Bangalore

DataCharge said...

Very wonderful informative article. I appreciated looking at your article. Very wonderful reveal. I would like to twit this on my followers. Many thanks! .
Data Analytics training in Bangalore

Pallavi reddy said...

i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
artificial intelligence training in chennai

Data Science Course in Bhilai - 360DigiTMG said...

Tremendous blog quite easy to grasp the subject since the content is very simple to understand. Obviously, this helps the participants to engage themselves in to the subject without much difficulty. Hope you further educate the readers in the same manner and keep sharing the content as always you do.

data science course in faridabad

Bhuvana said...

Excellent information Providing by your Article, thank you for taking the time to share with us such a nice article. Amazing insight you have on this, it's nice to find a website that details so much information about different artists...

DevOps Training in Hyderabad

Deekshitha said...

Informative blog
ai training in hyderabad

Ramesh Sampangi said...

If you're interested in getting a job in Python, look at the advanced Python training offered at Hyderabad from AI Patasala. Python Training in Hyderabad by trained experts at AI Patasala training center is the best option.
Python Course with Placements in Hyderabad

traininginstitute said...

This is really very nice post you shared, i like the post, thanks for sharing..
data science course

Gülçin Rıza said...

tokat eskort

afyon eskort

yozgat eskort

ankara eskort

sivas eskort

eskort

düzce bayan

manisa bayan

izmit bayan

görükle bayan

Gülçin Rıza said...

aydın masöz

bolu masöz

elazığ masöz

mardin masöz

tekirdağ masöz

van masöz

muş masöz

ağrı masöz

bayburt masöz

gümüşhane masöz

traininginstitute said...

Impressive. Your story always bring hope and new energy. Keep up the good work.
data science training in malaysia

Gülçin Rıza said...

uşak masöz

kilis masöz

osmaniye masöz

siirt masöz

muş masöz

bartın masöz

sivas masöz

şile masöz

ayvalık masöz

sultangazi masöz

Deekshitha said...

Informative blog
data science training in agra

Unknown said...

smm panel
smm panel
faturalı hatta kredi
faturalı hatta kredi
instagram takipçi satın al
binance komisyon indirimi
binance indirim kodu
instagram takipçi satın al
tiktok jeton hilesi

Unknown said...

bitcoin nasıl alınır
tiktok jeton hilesi
youtube abone satın al
gate io güvenilir mi
referans kimliği nedir
tiktok takipçi satın al
bitcoin nasıl alınır
mobil ödeme bozdurma
mobil ödeme bozdurma

Unknown said...

mmorpg oyunlar
İnstagram Takipci Satin Al
TİKTOK JETON HİLESİ
tiktok jeton hilesi
antalya saç ekimi
referans kimliği nedir
Takipci Satın Al
İnstagram Takipçi Satın Al
metin2 pvp serverlar
instagram takipçi satın al

Unknown said...

fon perde modelleri
Mobil onay
VODAFONE MOBİL ÖDEME BOZDURMA
Nft nasıl alınır
ANKARA EVDEN EVE NAKLİYAT
trafik sigortası
Dedektör
Site kurmak
aşk kitapları

Unknown said...

ümraniye alarko carrier klima servisi
üsküdar toshiba klima servisi
pendik daikin klima servisi
maltepe samsung klima servisi
kadıköy samsung klima servisi
tuzla mitsubishi klima servisi
çekmeköy vestel klima servisi
ataşehir vestel klima servisi
çekmeköy arçelik klima servisi

Unknown said...

bostansepeti.com
site kurma
ürünler
vezirsosyalmedya.com
postegro
sosyal medya yönetimi
surucukursuburada.com

traininginstitute said...

I love the way you write and share your nice! Very interesting and different! Keep it coming!
data science course

Post a Comment