Skip to content

Instantly share code, notes, and snippets.

View onurmatik's full-sized avatar

Onur Mat onurmatik

View GitHub Profile
@onurmatik
onurmatik / fabfile.py
Created June 25, 2012 18:09 — forked from justquick/fabfile.py
Simple fabfile to deploy my django projects on a gunicorn + nginx setup
import os
import sys
from fabric.api import abort, run, sudo, env, cd
from fabric.colors import red, green
from fabric.contrib.files import exists, put, upload_template
ROOT = '/home/jquick/code/'
WORKON = '/home/jquick/.virtualenvs'
VENVS = {
@onurmatik
onurmatik / TwitterRestFetch.py
Last active December 25, 2015 12:57
Fetch tweets according to the given parameters
"""
This script fetches tweets according to the given criteria and saves them in a CSV file.
How to use it:
- Install the dependencies:
$ pip install twython unicodecsv
- Go to https://apps.twitter.com and create an application. Under the "Keys and Access Tokens" tab get your keys and insert them below.
"""
- Takes a file which has one name on each line
- Searches for Twitter users; tries combinations for names longer than 2 words
- Returns the most probable username
"""
from twython import Twython
import itertools
from twython import Twython, TwythonStreamer
tokens = [
]
username = ''
rest_client = Twython(*tokens)
class Streamer(TwythonStreamer):
"""
FIXME: Cannot use C extensions. See below:
http://www.perrygeo.com/running-python-with-compiled-code-on-aws-lambda.html
http://stackoverflow.com/questions/34749806/using-moviepy-scipy-and-numpy-in-amazon-lambda
"""
from datetime import datetime
from urlparse import urlparse
from os import path
#encoding:utf-8
from datetime import datetime, timedelta
import unicodecsv
from delorean import parse
client = UserClient(
CONSUMER_KEY,
CONSUMER_SECRET,
ACCESS_TOKEN,
@onurmatik
onurmatik / gexf.py
Created March 8, 2017 00:33
Pure python gexf graph implementation
from xml.dom import minidom
from cStringIO import StringIO
class Graph():
"""
Create a Graph object and get its gexf representation.
Add nodes and edges using add_node() and add_edge() methods.
Use gexf() to get the file-like object containing the graph.
"""
@onurmatik
onurmatik / fetch_twitter_profile_images.py
Last active October 3, 2017 08:21
A Pyhton script to fetch Twitter user profile images and save them locally
import requests
import urllib
# 'usernames.txt' contains a list of Twitter usernames; one at each line
f = open('usernames.txt')
# Photo addresses are saved into 'images.txt'
out = open('images.txt', 'w')
# for each username, the photo file itself is save under 'photo/' folder
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import re
import json
import requests # pip install requests
profile_pat = re.compile('<script type="text/javascript">window\._sharedData = (.*);</script>')
username = 'onurmatik' # instagram username to check its posts
# The exception handling is excluded for brevity
response = requests.get('https://www.instagram.com/%s/' % username)
match = profile_pat.findall(response.text)