Attempting to Learn Git/Github Again

A few months ago, I was going through a Treehouse tutorial on PHP, and I finally started to understand git and Github. I switched to learning something different, and forgot all of the things I had learned. Since then, I’ve just been using Dropbox to keep my programming in sync. It works pretty well, but the thing about Github is that it gives you a record of changes, along with encouragement to post code publicly. As a beginner, it seems like a lot of trouble, but I can start to see the benefits.

Benefits of Github to a Beginner

  • Can see all changes to the files
  • Can revert back to any version
  • Allow’s for easy posting of code publicly
  • Nice visualization of history
  • Still waiting to learn more about the collaboration parts…

Where to Learn

I’m sure there are a lot of places to learn, and even some popular tutorials have sections on it. The best place to get started is Code School’s Try Git Course (free). It lets you avoid some of the headaches in getting things setup, but still get the same view. I actually took notes of this to put in a type of cheatsheet because I don’t want to have to go searching around on Google the next time I want to know how to do something.

Git Notes in Workflowy – View Only

Python with Evernote API Struggles – Part 3

Getting Note Content

The next step after viewing a list of note titles is to be able to read the contents of the note.  From the documentation,  I see two main ways to get the info. The first is getNoteContent() and returns the note body, with the ENML syntax. The second option is called getNoteSearchText() and returns the searchable text from the note.

The first option would be the best,  except there is no available ENML to HTML converter available. I suppose that would be a decent project, but I’m not sure how interesting.

Using Dictionaries for Options and to Select Notes

The biggest frustration with getting note content was that in order to pick a note and get the data for it, you had to enter the GUID in the function call. A more experienced programmer would have done something to make that easier from the start. But, I’ve figured it out the hard way, which should be more helpful in remembering. The plan is to add a dictionary with the number as the key and the GUID as the value. That way, when I show a list of 10 ten notes and want to show the contents of one, I just type the number it is, instead of using the whole GUID. Really basic stuff, I know, but using lists and dictionaries to solve problems is still new to me.

I had some trouble with this before I changed

getNoteKey = raw_input('Enter number of note to retrieve\n/>/>')


getNoteKey = int(raw_input('Enter number of note to retrieve\n>>'))

Working Version

Poorly coded working version to get the content/search text of a note using the dictionary created when listing notes.

    if option_choice == '6':
        getNoteKey = int(raw_input('Enter number of note to retrieve\n>>'))
        getguid = note_dict[getNoteKey]
        print getguid + ' content: \n'
        print note_store.getNoteContent(auth_token, getguid)
    if option_choice == '7':
        getNoteKey = int(raw_input('Enter number of note to retrieve\n>>'))
        getguid = note_dict[getNoteKey]
        print getguid + ' content: \n'
        print note_store.getNoteSearchText(auth_token, getguid, True, False)


Python with Evernote API Struggles – Part 2

Part 1

So far, I had succeeded in making a very basic command line interface with Evernote using the API and the Python SDK. I don’t expect this to be useful for anything in the future as the other day I have already found a fully featured command line application for Evernote. But, this is the easiest way I can think of to practice these things. I’m still not sure about the options for converting Python scripts into web interfaces or GUI interfaces. That is definitely down the road to learn.

Going through this, one of the biggest struggles is dealing with the complexity of the SDK. With a beginner’s understanding of classes, it is pretty tough to look at the source in the SDK and figure things out without a lot of help from Google. If I was less interested in Evernote, and just wanting to learn some basic API stuff, I would probably be better off with a simpler practice example.

Showing a List of Notes

Next step, would be an option to show a list of notes. The first place I looked was Brett Kelly’s gist page, because he has a lot of simple examples in Python. I found one example that prints the id and title of each note returned. I tried that, but I think the problem was how the SDK files were imported at the top:

import evernote.edam.notestore.NoteStore as NoteStore
import evernote.edam.type.ttypes as Types

I looked through the source code and found the NoteFilter class in the edam/notestore/ file. I added the following reference and changed how the NoteFilter was setup and it was corrected. Also, changed it to findNotes based on another example, but I’m not sure of the difference.

import evernote.edam.notestore.ttypes as NoteStoreTypes
filter = NoteStoreTypes.NoteFilter()
filter.ascending = False
notelist = note_store.findNotes(auth_token,filter,0,10)
noteCount = 0
for note in notelist.notes:
noteCount += 1
print str(noteCount) + ' - ' + note.title

Evernote SDK Structure

Python with Evernote API Struggles

Trying to record some beginner frustrations with trying to connect to the Evernote API using Python. To be clear the only API’s I’ve tried to connect to before were the one’s in Codecademy’s API lessons. In those examples, they make it a little too easy as far as setting things up which it seems is one of the most difficult parts for a beginner.

The first place to go to get started with the Evernote API is Their site has links to the SDK for different languages. These are the building blocks of how to connect, and make it possible for a beginner to have a chance. The first action I took was to download this and unzip it.

I looked at the code in the sample program and saw the comment about having to put in the Developer token if you just wanted to connect for individual testing.

Problem 1: Using the wrong developer token

When I entered my developer token the first time, I mistakenly used the API instead of the token. To get a token for a sandbox account, read this page and find the link to add one API Authentication

Once I got that working, I tried to run the sample program within the SDK files named

Problem 2: Cannot find required files

The SDK example uses files within the SDK, but the sample files import commands didn’t exactly match up with where the sample file was located. The SDK said to put EXPORT ../..lib before the python command, but I don’t know if that works in Windows. What I did was end up just moving the sample file to where it needed to be based on the import commands.

Problem 3: No oauth2 found

One of the examples (might be a different example file) from Brett Kelly required oauth2. I googled how to install it and none of it made any sense. I eventually found something that said to install ez_setup or easy_install.

Problem 4: How to install easy_install?

To be honest, I don’t remember what I did here.

Now that I’m trying to write this out, I think I tried the example with oauth2 before I figured out some other things and don’t think I’ve got that one working yet. I did get the to work on a sandbox account (sandbox account is a separate account you create to test connecting to the API with) This file lists the notebooks in your account and attempts to add a note. I got that to work and after that, I took it just one step further and looked at the API docs to figure out how to add tags to a note created through the API.

Problem 5: Created tags came out as multiple one character tags instead of one single tag.

When adding the tag, I tried to use a string on the first attempt. My tags came across as a bunch of one character tags. I looked at the documentation and found out that tags need to be entered as a list. I tested that and it worked perfectly.

The lesson here is that working with API’s is not impossible for someone who is newer to programming. The extent of my Python learning is 30-some Learn Python the Hard Way exercises as well as the Python track at Codecademy. It is pretty essential to have at least one piece of sample code that shows how to connect. Building off of that is much easier than trying to write all of the connection logic from scratch. Other than that keep it in mind to break the problem down into small steps and that working with API’s as a beginner involves a LOT of upfront frustration but it can be done.

Daily Progress: Day 6

Python Class Tutorial

So, this is the basic format of a class in Python…

class Classname(object):

Where the argument is the class that Classname inherits from.

Why do classes always have __init__() ?

This is what happens when the class is initialized. It takes the arguments and sets the properties of the object to the arguments passed in. This still doesn’t make a lot of sense to me.

class Animal(object):
	def __init__(self, name): = name

zebra = Animal("Jeffrey")


Daily Progress: Day 5

Tried to look around for some ways to visualize the data I’m getting from this in Python. Right now, I’m a lot more comfortable working with Excel, so I’ll stay there for now. Next problem I’d like to look into is that my script creates a frequency list of words. Right now, one of the highest words is “e:” which is because all of my chat lines start with “me:” and it is cutting the first letter off somewhere.

Daily Progress: Day 4

Went back and looked at my chat analyzer code today and realized I was using an extra function that I didn’t need.  After I had a list put together for each line I was adding that to another list and then using the following to try and put each row into a csv file.

     values = [outputLine, subject, chatDate, chatFrom, chatTo, lastTime, lastSpeaker, line]

Changed to:


Once I fixed that the output to the csv file was just what I expected. There are still a lot of things to work on,  but this was a big hurdle and it is much farther than I got 2 years ago while going through Learn Python the Hard Way. Now, I have a 17MB .csv file that looks the way I want it to. Next, I’ll need to think some more about what types of things I want to see, and how that data needs to be setup to see that. The example above has a lot of repeated information about each text file. The only thing that is really important is what the date was. The subject, from, and to lines are always generic and add little value.

Daily Progress: Day 3

Continuing Python Review

Python Codecademy track, Part 7: Lists and Functions
I’m a little disappointed to be reviewing the things I’ve just reviewed, but it is going pretty fast because I’m getting better at the syntax of how to do these things. I did get tripped up on one review question.

Problem is to take the example of a function adding two parameters and change it to add any number of parameters.

m = 5
n = 13
#function goes here
def myFun(x, y):
	return x + y
print (myFun(m,n))

I went with this

m = 5
n = 13
#function goes here
def myFun(*args):
	return sum(*args)
print (myFun(m,n))

and got an error. I checked the hint, which gave the answer, and changed my code to match. I knew at once that it the parameter was *args, but I wasn’t for sure that sum() was a function you could use, and I also didn’t know to use args as the parameter as opposed to *args.

m = 5
n = 13
#function goes here
def myFun(*args):
	return sum(args)
print (myFun(m,n))

Reminder on how to loop through a certain group in a list

In all of the things I’ve been doing lately I’ve only been looping through the entire list

for item in list:

But when you want to only loop through the first 3 items

list = (1, 2, 3, 4, 5, 6)
for item in range(0, 3):

I still don’t fully understand why the range here is 0 to 3, but only returns 3 items. I think this is similar to how slicing works, but it is different than arrays. That’s a good problem for another day.

Answer Received

The next section of the tutorial explains the range function. What it does is creates a list.

print range(0, 2)
print range(1, 2)
print range(0, 3)
[0, 1]
[0, 1, 2]

In the previous example, range(0, 3) created the list [0, 1, 2] and then looked in the list at those positions to return 1, 2, 3. I was overlooking that the for loop didn’t necessarily have anything to with the list until after the range of values to lookup was created.

Getting better at noticing the things I always forget

One huge benefit of writing out these posts is that when I am shown something that I have already seen I’m starting to notice if I remembered it or not. Here is another function that makes a lot of sense when it is explained, but I wouldn’t have thought of using unless it was explained right before the problem came up.

board = []
for x in range(0, 5):
	#board.append([str('O')] * 5)
	board.append(['O'] * 5)
def print_board(list):
	for row in list:
		print row
['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']

How do you turn the output into?


The answer is the join() function

board = []
for x in range(0, 5):
	board.append([str('O')] * 5)
	#board.append(['O'] * 5)
def print_board(list):
	for row in list:
		print " ".join(row)

Daily Progress: Day 2

Lists and Dictionaries

Going through the Lists and Dictionaries section of the Codecademy Python track today. The list stuff isn’t too bad, but the dictionary parts are hard to remember, after the tutorial is over. One of the really useful things is to notice the difference between looping through a set of keys and looping through the values the keys point to.

Dict = {
    "A" : "Apple",
    "B" : "Banana",
    "C" : "Carrot"
for key in Dict:
    print key + " -- " + Dict[key]


A -- Apple
C -- Carrot
B -- Banana

Which Error is it?

Here is an example of an error I ran into. At first I thought it was something to do with the unicode format the error code gives, but after looking at the forums, I checked my code against another person, and it turns out I had the indentation wrong on my return. This is a good example of an easy mistake that wasn’t as frustrating as it could have been because the answer was close enough to find.
Error with Indents

def fizzCount(x):
	count = 0
	for item in x:
		if item == "fizz":
			count += 1
	return count

Small Error: Concatenating Strings and Numbers

The next small error I came up against was trying to concatenate strings and numbers. I have run into this before so I found it before looking at the hint, which explained the error if you didn’t know what the problem was.

prices = {
	"banana": 4,
	"apple": 2,
	"orange": 1.5,
	"pear": 3

stock = {
	"banana": 6,
	"apple": 0,
	"orange": 32,
	"pear": 15

for item in stock:
	print item
	print "price: " + prices[item]
	print "stock: " + stock[item]


prices = {
	"banana": 4,
	"apple": 2,
	"orange": 1.5,
	"pear": 3

stock = {
	"banana": 6,
	"apple": 0,
	"orange": 32,
	"pear": 15

for item in stock:
	print item
	print "price: " + str(prices[item])
	print "stock: " + str(stock[item])

Daily Progress: Day 1

Working on going through the Codecademy Python track again. The reason I am going through it again is that I’m working on making a program to go through chat logs that I’ve downloaded from Gmail and analyzing them using Python. While working on this, I keep running into too many roadblocks because I have to keep looking up the basics. The specific part of my project that has me blocked right now is putting the chat log lines into a similar format.  For example, right now they would look similar to this:

Subject: Chat with Joe
From: Joe <>
Date: 1/17/2013 11:33 AM
To: <>

11:33 AM me: hey
	11 minutes
11:45 AM Joe: yeah
	9 minutes
11:54 AM Joe: whats up?
11:56 AM me: nothing
11:57 AM Joe: OK
  gotta go

What I would prefer to work with is a standardized format like:

From    To     Date    Time      Speaker Message
Joe     me     1/17/13 11:33 AM  me      hey
Joe     me     1/17/13 11:45 AM  Joe     yeah

What I’m trying first is to put them in a 2d array and I keep having issues with filling it and then also looping through it correctly once I do have it setup. At the end of today I am through Part 4 of the Python track which is about Functions. The next two sections are on Lists and Dictionaries, and I think those will help me in this section more than anything. The stuff I’ve learned in those didn’t stay with me very well the first time through.