This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import permutations | |
def ret_unique(a): | |
'''returns a copy of the list with: | |
order preserved, | |
permutations removed, | |
repeat elements removed''' | |
for i,el in enumerate(a): | |
b = permutations(el,3) | |
for el1 in b: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib | |
import urllib | |
import urllib2 | |
import re | |
import csv | |
import logging | |
from cookielib import CookieJar | |
class pyGTrends(object): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
#this one line is all you need to set up a database | |
connection = sqlite3.connect('example') | |
#a cursor object is used to execute queries against the db | |
cursor = connection.cursor() | |
#create a table | |
cursor.execute('CREATE TABLE example (id real, value text)') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#odd quirk found on Python | |
#say you have a list of values, and you want a dict with keys for each item, and each value an empty array. | |
#I found myself in this situation, and I decided to do it like this: | |
l = ['a','b','c'] | |
gg = dict(zip(l,[[]]*3)) | |
gg | |
#however, when you try and put a value into one of those arrays: | |
gg['a'].append(1) | |
gg | |
#1: {'a': [1], 'b': [1], 'c': [1]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import py2neo | |
import datetime | |
#where we write it | |
f_name = 'DBREPORT_%s.txt' % datetime.datetime.today().strftime('%Y-%m-%d') | |
#overwrite anything previous | |
with open(f_name,'wb') as f: | |
f.write('REPORT COMPILATION STARTED AT %s' % datetime.datetime.now()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pandas.core.api import DataFrame | |
from pandas.tseries.tools import to_datetime | |
#save me at site-packages\pandas\io\cypher.py | |
def read_cypher(cypher, con, index_col=None, params = {},parse_dates = None, columns= None): | |
''' | |
Run a Cypher query against the graph at con, put the results into a df | |
Parameters |