Skip to content

Instantly share code, notes, and snippets.

View m7catsue's full-sized avatar
🎯
Focusing

Lu Yaxin m7catsue

🎯
Focusing
  • Chengdu, China
View GitHub Profile
@m7catsue
m7catsue / WechatSmartWish.py
Created April 14, 2017 09:08 — forked from littlecodersh/WechatSmartWish.py
Demo of sending smart wishes through wechat.
#coding=utf8
import itchat, time
SINCERE_WISH = u'祝%s新年快乐!'
REAL_SINCERE_WISH = u'祝%s新年快乐!!'
def send_wishes():
friendList = itchat.get_friends(update=True)[1:]
for friend in friendList:
# 如果不是演示目的,把下面的方法改为itchat.send即可
@m7catsue
m7catsue / sentiment.py
Created April 10, 2017 08:24 — forked from bbengfort/sentiment.py
An end-to-end demonstration of a Scikit-Learn SVM classifier trained on the positive and negative movie reviews corpus in NLTK.
import os
import time
import string
import pickle
from operator import itemgetter
from nltk.corpus import stopwords as sw
from nltk.corpus import wordnet as wn
from nltk import wordpunct_tokenize
#http://geekgirl.io/concurrent-http-requests-with-python3-and-asyncio/
Concurrent HTTP Requests with Python3 and asyncio
My friend who is a data scientist had wipped up a script that made lots (over 27K) of queries to the Google Places API. The problem was that it was synchronous and thus took over 2.5hours to complete.
Given that I'm currently attending Hacker School and get to spend all day working on any coding problems that interests me, I decided to go about trying to optimise it.
I'm new to Python so had to do a bit of groundwork first to determine which course of action was best.
@m7catsue
m7catsue / download_multiple.py
Created March 23, 2017 07:30 — forked from Hammer2900/download_multiple.py
Use asyncio and aiohttp to asynchronously download multiple files at once and handle the responses as they finish
import asyncio
from contextlib import closing
import aiohttp
async def download_file(session: aiohttp.ClientSession, url: str):
async with session.get(url) as response:
assert response.status == 200
# For large files use response.content.read(chunk_size) instead.
async def main():
coroutine1 = do_some_work(1)
coroutine2 = do_some_work(2)
coroutine3 = do_some_work(4)
tasks = [
asyncio.ensure_future(coroutine1),
asyncio.ensure_future(coroutine2),
asyncio.ensure_future(coroutine3)
]
import re
import random
import base64
from scrapy import log
class RandomProxy(object):
def __init__(self, settings):
self.proxy_list = settings.get('PROXY_LIST')
fin = open(self.proxy_list)
@m7catsue
m7catsue / middlewares.py
Created February 18, 2017 11:55 — forked from pkmishra/middlewares.py
Scrapy middlewares for random agent list and proxy server usage.
import os
import random
from scrapy.conf import settings
class RandomUserAgentMiddleware(object):
def process_request(self, request, spider):
ua = random.choice(settings.get('USER_AGENT_LIST'))
if ua:
request.headers.setdefault('User-Agent', ua)
class ProxyMiddleware(object):
@m7catsue
m7catsue / bokeh_datatable_filter_and_send.py
Created January 19, 2017 04:40 — forked from dennisobrien/bokeh_datatable_filter_and_send.py
Filter a Bokeh DataTable using multiple filter widgets and send the filtered results to the next step (in this case a blank window). Assumes the data table is not editable. Runs in a Jupyter notebook.
from bokeh.io import output_notebook
output_notebook()
from bokeh.io import show, vplot
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.models.layouts import HBox
from bokeh.models.widgets import Button, DataTable, Select, Slider, TableColumn
from bokeh.sampledata.periodic_table import elements
@m7catsue
m7catsue / bokeh_datatable_filtered.py
Created January 19, 2017 03:38 — forked from dennisobrien/bokeh_datatable_filtered.py
Filter a Bokeh DataTable using multiple filter widgets. Runs in a Jupyter notebook.
import bokeh.embed
import bokeh.io
import bokeh.models
import bokeh.models.widgets
import bokeh.plotting
import pandas as pd
from pandas_datareader import wb
bokeh.plotting.output_notebook()
@m7catsue
m7catsue / descriptors.py
Created December 28, 2016 06:29 — forked from jsborjesson/descriptors.py
Python descriptors made easy
import re
from weakref import WeakKeyDictionary
class AdvancedDescriptor(object):
"""
Base class for descriptors, is hard to understand but works for most cases.
from https://www.youtube.com/watch?v=P92z7m-kZpc
"""
def __init__(self, name=None):