Uncategorized

Twitter Research – Day Thirteen

Day 13, More Twitter App (go to project overview)

The production Python code I’ve worked with professionally, thus far, has been a bit cumbersome because it hasn’t used enough classes imho.  Up until today, I hadn’t really known how to build classes that were solely for organizing an entity.  I happened upon this code base, which has what I think is a pretty good way of building an entity class from a dictionary.  So, I’m going to do this in my Twitter class.

John Somnez gives good advice

Side note:  As I’m trying to perfect my handling of data in my TwitterAnalyze app, I get an email from John Somnez entitled “Why success favors speed and not perfection”.   Haha.  I get it, universe.

After spending a bit of time getting the class thing to work, I realized that I have to serialize those classes when I return them from my view.  So, I’ve added quite a bit of work just so I could use classes instead of straight dictionaries.  I think I’m going to pursue this, though.  It seems like deeper Python knowledge that I should know even though it’s bull-hockey for what I’m currently working on.

Definition of Bull-hockey: Overkill

In the end, I kept with classes.  I read a bunch of info that only served to convince me further that Python is BIG.  I ended up combining advice to use a list comprehension coupled with a class that derives from JSONEncoder (thank you people on stack overflow!).  Ouch.

Conserving tweets

So as not to use up my tweet allocation, I pulled the data from one query into a .json file that I can just read.  It’s formatted just like the data returned from Twitter, so this allowed me to test a bunch of times with no hit on my allocated query count.  Next, I’m going to write some (one) test(s).  Maybe I can use that data in my test.  Currently, I’m ignoring the file with the data in .gitignore, so I’m not committing it.  But, I think it would be helpful for others trying to navigate Twitter data.  I’m wondering if I could put it out in Github if it was one of my Tweets.  Maybe it’s ok to put it out in Github as is.  I feel a bit worried about following Twitter’s developer guidelines.  I think I am, but I don’t want to get on Twitter’s wrong side!

Logging is a big deal

I have intermittently been spending time on logging.  It’s not working great, but, it’s important. I’m am going to shelve it for now knowing that I have to spend some time doing it right.  I think the logs should be complete and visible.  I’m not there yet.

Test automation is a big deal

Consequently, next Pluralsight’s “Unit Testing with Python” by Emily Bache. Or not.  I got a bit into this and decided to just use Django docs to tackle testing.  I don’t want to use any packages outside of the basics provided by Django.  I found this post by Tobias Lorenz helpful for setting up view tests.  But, when running these tests, I realized that my views are not class based views, so this method doesn’t work.  This led me down the path of class based vs function based views.  

Aha after aha up in here!

While doing this whole thing, I’ve realized that, while I have been able to add a bunch of code to an existing Django project with a great deal of success, there are a ton of things that I’ve not been exposed to enough for them to have sunk in.  When you build a project from scratch and you have to deal with each and every decision, you end up learning a ton.

But, back to the show…I think I’ll use class based views.  I’ve read some stuff that makes me think some people who know way more than me like function based views, but it seems like the Django docs like class based views.  And, alas, I’ve managed to set up test cases for all of my views and environment variables with the exception of the view that actually returns the Twitter data (is that the main view?).  I would like to set that test up so that it doesn’t actually make a call to twitter.  I’d just rather test that the twitter code can handle the test data I’ve created so, next, I’ll look into mocks.  Of course, there’s a ton of info.  But, this stack overflow post has a pretty concise way. I’m going to attempt to do the mock with the “MyGreatClass…” example by Johannes Fahrenkrug.  

Stackoverflow is a whole thing!

Side note: I finally, for the first time ever, upvoted something I used.  Not sure why I haven’t thought I should thank people for their answers.  I use stackoverflow all the gosh dang time.

However, my vote did not count because I have no reputation.  Here are the reputation rules.  These are kinda scary. I think a person could really get caught up in that.  By a person, I mean this person and I don’t have time for that…or do I? Maybe it’s a good way to get noticed for paying work.  I don’t know.

My approach depends on who is paying me

Amazing that a person who works for someone else cannot take these little side trips.  At least if someone was paying me right now, I would not feel ok about researching how stack overflow reputations work.  I’d just get my answer and hurry on out of there.  When you work for others, you feel obligated to code as much as possible as quickly as possible.  Maybe, sometimes, squandering quality a bit.

Leave a Reply

Your email address will not be published. Required fields are marked *

Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from Youtube
Vimeo
Consent to display content from Vimeo
Google Maps
Consent to display content from Google
Spotify
Consent to display content from Spotify
Sound Cloud
Consent to display content from Sound