Thursday, January 30, 2014
Learning Ember.js
Ember.js is like Angular on steroids. Strangely enough, some of the code reminds me of Python microframeworks like Bottle.
Tuesday, January 28, 2014
Understanding Python Decorators
As I learn more about web frameworks in Python, I am getting more exposure to Python decorators. Decorators seem easy to use, but I have a hard time understanding them. Hoping this article will clear them up:
http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/
http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/
Saturday, January 25, 2014
Question About Rails Asset Pipeline
From staring at my old code and poking around the web, I figured out that the Rails Asset Pipeline loads up all of your assets (Javascript, CSS, etc.) and smashes them together into a manifest file for fast and easy digestion. When does this happen? When your app starts up?
Monday, January 13, 2014
Scraping Success!
Managed to send out a Spider using Scrapy to scrape a website and save the results in a JSON file! Now I just need to work on some formatting for the JSON file.
Writing A Spider In Python
Even though I successfully scraped a website with Ruby and Nokogiri, I decided to continue explore scraping websites with Python and Scrapy. Today I wrote my first spider in Python. You can watch my progress in my github repository:
https://github.com/cspears2002/scrapestat
I need to look up deploying Python to Heroku:
https://devcenter.heroku.com/articles/getting-started-with-python
Actually, deploying to Heroku might not make any sense. This is not a web app.
Friday, January 10, 2014
Running A Quick Webserver With Python
Python never ceases to amaze me. Here is how to run a quick web server using Python from the command line:
unknownc8e0eb148153:D3 christopherspears$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
127.0.0.1 - - [10/Jan/2014 10:53:35] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [10/Jan/2014 10:53:36] "GET /data.tsv HTTP/1.1" 200 -
127.0.0.1 - - [10/Jan/2014 10:53:47] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [10/Jan/2014 10:53:47] "GET /data.tsv HTTP/1.1" 200 -
127.0.0.1 - - [10/Jan/2014 10:54:13] "GET / HTTP/1.1" 200 -
As you can see, the server is serving up the data.tsv file in the directory. Here are some helpful links:
http://www.linuxjournal.com/content/tech-tip-really-simple-http-server-python
http://stackoverflow.com/questions/12647196/how-do-i-shut-down-a-python-simplehttpserver
unknownc8e0eb148153:D3 christopherspears$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
127.0.0.1 - - [10/Jan/2014 10:53:35] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [10/Jan/2014 10:53:36] "GET /data.tsv HTTP/1.1" 200 -
127.0.0.1 - - [10/Jan/2014 10:53:47] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [10/Jan/2014 10:53:47] "GET /data.tsv HTTP/1.1" 200 -
127.0.0.1 - - [10/Jan/2014 10:54:13] "GET / HTTP/1.1" 200 -
As you can see, the server is serving up the data.tsv file in the directory. Here are some helpful links:
http://www.linuxjournal.com/content/tech-tip-really-simple-http-server-python
http://stackoverflow.com/questions/12647196/how-do-i-shut-down-a-python-simplehttpserver
Tuesday, January 7, 2014
Scrapy is a framework
Weird. Scrapy is actually a framework. I feel like I am working in Django or Ruby on Rails again.
Wednesday, January 1, 2014
Scraping A Website With Python
Going to explore scraping a website with Python and Scrapy (http://scrapy.org/).
Python Installation Odds And Ends
Forgot to add this to the bottom of my .bash_profile file:
#Python
export PATH=/usr/local/share/python:$PATH
My site-packages folder is installed here:
/usr/local/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
#Python
export PATH=/usr/local/share/python:$PATH
My site-packages folder is installed here:
/usr/local/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Which virtual environment am I working on?
Here is how to find out (as well as set and exit the virtual environment):
Christophers-MacBook-Pro-2:scrapestat christopherspears$ workon
scrapestat
Christophers-MacBook-Pro-2:scrapestat christopherspears$ workon scrapestat
(scrapestat)Christophers-MacBook-Pro-2:scrapestat christopherspears$ echo $VIRTUAL_ENV
/Users/christopherspears/.virtualenvs/scrapestat
(scrapestat)Christophers-MacBook-Pro-2:scrapestat christopherspears$ deactivate
Christophers-MacBook-Pro-2:scrapestat christopherspears$ echo $VIRTUAL_ENV
Christophers-MacBook-Pro-2:scrapestat christopherspears$ workon
scrapestat
Christophers-MacBook-Pro-2:scrapestat christopherspears$ workon scrapestat
(scrapestat)Christophers-MacBook-Pro-2:scrapestat christopherspears$ echo $VIRTUAL_ENV
/Users/christopherspears/.virtualenvs/scrapestat
(scrapestat)Christophers-MacBook-Pro-2:scrapestat christopherspears$ deactivate
Christophers-MacBook-Pro-2:scrapestat christopherspears$ echo $VIRTUAL_ENV
Setting Up virtualenvwrapper on Mac OS X
The software virtualenvwrapper is a wrapper around virtualenv that has a lot of neat functions that allows the user to manage multiple virtual environments. I decided to install the wrapper today.
First I ran the following:
$ pip install virtualenvwrapper
Then inside of the .bash_profile file inside of my home directory I added the following lines.
# virtualenvwrapper stuff
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/PyDevel
source /usr/local/bin/virtualenvwrapper.sh
Finally I sourced .bash_profile:
$ source ~/.bash_profile
Now I have a directory called .virtualenvs/ inside of my home directory. Inside of my home directory, I create the 'PyDevel' directory.
Then I created my project's directory:
Christophers-MacBook-Pro-2:~ christopherspears$ mkproject scrapestat
New python executable in scrapestat/bin/python2.7
Also creating executable in scrapestat/bin/python
Installing Setuptools..............................................................................................................................................................................................................................done.
Installing Pip.....................................................................................................................................................................................................................................................................................................................................done.
Creating /Users/christopherspears/PyDevel/scrapestat
Setting project for scrapestat to /Users/christopherspears/PyDevel/scrapestat
First I ran the following:
$ pip install virtualenvwrapper
Then inside of the .bash_profile file inside of my home directory I added the following lines.
# virtualenvwrapper stuff
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/PyDevel
source /usr/local/bin/virtualenvwrapper.sh
Finally I sourced .bash_profile:
$ source ~/.bash_profile
Now I have a directory called .virtualenvs/ inside of my home directory. Inside of my home directory, I create the 'PyDevel' directory.
Then I created my project's directory:
Christophers-MacBook-Pro-2:~ christopherspears$ mkproject scrapestat
New python executable in scrapestat/bin/python2.7
Also creating executable in scrapestat/bin/python
Installing Setuptools..............................................................................................................................................................................................................................done.
Installing Pip.....................................................................................................................................................................................................................................................................................................................................done.
Creating /Users/christopherspears/PyDevel/scrapestat
Setting project for scrapestat to /Users/christopherspears/PyDevel/scrapestat
Subscribe to:
Posts (Atom)