Skip to content

Instantly share code, notes, and snippets.

View rsarai's full-sized avatar
🏜️

Rebeca Sarai rsarai

🏜️
View GitHub Profile
@rsarai
rsarai / elementarscraper.py
Created August 26, 2017 23:58
Just a quick example of how to use Beautiful Soup
import requests
from bs4 import BeautifulSoup
url = 'http://www.someurl.com.br/products'
headers = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'
}
r = requests.get(url, headers=headers, timeout=5)
@rsarai
rsarai / products_spider.py
Last active August 27, 2017 01:53
Spider for retrieve all the products from a web site and another one for download images and renaming them.
import scrapy
from scrapymercado.items import ProductsItem
from scrapymercado.constants import URL
class ProductsSpider(scrapy.Spider):
name = "products"
def start_requests(self):
max_page_number = 67
import scrapy
from scrapymercado.items import ProductsItem
from scrapymercado.constants import URL
class ProductImgSpider(scrapy.Spider):
name = "productsimg"
def start_requests(self):
max_page_number = 67
import scrapy
from scrapy.contrib.pipeline.images import ImagesPipeline
from scrapymercado.constants import URLS_AND_NAMES
class ScrapymercadoPipeline(ImagesPipeline):
def get_media_requests(self, item, info):
for image_url in item.get('image_urls', []):
yield scrapy.Request(image_url, meta={'filepatch': URLS_AND_NAMES.get(image_url)})
export function getDayOfWeek(date) {
const dayOfWeek = new Date(date).getDay();
return isNaN(dayOfWeek) ? null : ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][dayOfWeek];
}
export function getMonthName(date) {
const monthNumer = new Date(date).getMonth();
return isNaN(monthNumer) ? null : ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'][monthNumer];
}
@rsarai
rsarai / admin.py
Last active June 30, 2022 14:34
How to create a simple confirmation view on Django Admin like the default delete view works
from django import forms
from django.contrib import admin
from django.template.response import TemplateResponse
class RegularCreationAdminForm(forms.ModelForm):
class Meta:
model = ReactivationCoupon
fields = [
@rsarai
rsarai / Problem Solving
Created December 3, 2018 16:25 — forked from geek-id/Problem Solving
Problem Solving in Linux
[error]
ImportError: No module named '_gdbm'
[solved]
sudo apt-get install python3.5-gdbm
[error]
ImportError: No module named 'apt_pkg'
[solved]
locate apt_pkg.so
sudo ln -s /usr/lib/python3/dist-packages/apt_pkg.cpython-34m-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/apt_pkg.so
import json
import falcon
FAKE_DB_MOVIE = [{
"Title": "The Alienist",
"Year": "2018",
"Rated": "TV-MA",
"Released": "22 Jan 2018",
"Runtime": "60 min",
"Genre": "Drama, Mystery",
@rsarai
rsarai / app.py
Last active January 19, 2019 15:16
import falcon
from .movies import Movie
api = application = falcon.API()
movie = Movie()
api.add_route('/movies', movie)