Skip to content

Instantly share code, notes, and snippets.

import re
from collections import namedtuple
from spidermon import Monitor, MonitorSuite, monitors
def check_coverage(expected, current, parent_field=None):
CoverageResult = namedtuple("CoverageResult", ("status", "failures"))
failures = []
for field, value in expected.items():
from spidermon import Monitor, MonitorSuite
from spidermon.core.suites import MonitorSuite
from spidermon.runners import TextMonitorRunner
from spidermon.core.actions import Action
class StandaloneMonitor(Monitor):
def test_number_of_errors(self):
num_errors = self.data["num_errors"]
self.assertLessEqual(num_errors, 10, msg="Many errors!")
from ics import Calendar
from telegram.ext import Updater, CommandHandler
def ics_calendar():
with open("lhc.ics", "r") as f:
calendar = Calendar(f.read())
return calendar
import datetime
import itertools
import json
from urllib.parse import urljoin
import requests
from ics import Calendar, Event
from parsel import Selector
import datetime
import os
from scrapy import signals
from scrapy.exceptions import NotConfigured
from scrapy.utils.project import data_path
def json_serial(obj):
"""JSON serializer for objects not serializable by default json code"""
@rennerocha
rennerocha / flatten.py
Created June 29, 2017 13:21
Citrusbyte - Array flatten function
def recursive_flatten(nested):
"""Return a flatten array from an arbitrarily nested array of integers
This function is recursive so it could not be used with lists with high
levels of nesting to avoid recursion errors
>>> recursive_flatten([])
[]
>>> recursive_flatten([1, 2, 3])
@rennerocha
rennerocha / packtpub_free_ebook.py
Created March 30, 2017 10:59
Return name of today's free ebook of Packtpub
import datetime
import re
import urllib2
def today_packtpub_free_ebook():
FREE_EBOOK_URL = 'https://www.packtpub.com/packt/offers/free-learning'
try:
request = urllib2.Request(FREE_EBOOK_URL)
response = urllib2.urlopen(request)
except:
@rennerocha
rennerocha / packtpub.py
Created March 30, 2017 10:39
Check today's free ebook from Packpub
import datetime
import os
import re
import socket
import Tkinter as Tk
import urllib2
import webbrowser
FREE_EBOOK_URL = 'https://www.packtpub.com/packt/offers/free-learning'
@rennerocha
rennerocha / cartao_itau_moneylog.py
Created April 9, 2014 14:45
conversor cartão itau para moneylog
#!/usr/env/python
import re
import sys
def read_credit_card_data(purchases_file, year, tags=None):
with open(purchases_file, 'r') as purchases_data:
purchases = purchases_data.readlines()
@rennerocha
rennerocha / ics_lhc.py
Last active August 29, 2015 13:56
ics calendar for LHC
# -*- coding: utf-8 -*-
from datetime import datetime
from icalendar import Calendar, Event
import json
import os
import urllib2
if __name__ == '__main__':
LHC_ICS_FILE = '/home/hscps/hsc.tia.mat.br/lhc.ics'