Skip to content

Instantly share code, notes, and snippets.


Darwing Medina darwing1210

  • Nicaragua
View GitHub Profile
darwing1210 /
Created Jan 29, 2020
Script to download files in a async way, using Python asyncio
import os
import asyncio
import aiohttp # pip install aiohttp
import aiofiles # pip install aiofiles
REPORTS_FOLDER = "reports"
FILES_PATH = os.path.join(REPORTS_FOLDER, "files")
def download_files_from_report(urls):
darwing1210 /
Last active Apr 19, 2022
Django command to create users from a CSV file
import csv
from import BaseCommand, CommandError
from django.contrib.auth import get_user_model
from django.utils.crypto import get_random_string
class Command(BaseCommand):
""" import_users --csv='/Users/user/usuariosweb.csv' --encoding='iso-8859-1'"""
help = 'Imports users based on a CSV file'
darwing1210 /
Last active Feb 15, 2018
Django Command to reset apps tables
from io import StringIO
from optparse import make_option
from django.apps import apps
from import AppCommand, CommandError
from import no_style
from import call_command
from django.db import connections, transaction, DEFAULT_DB_ALIAS
darwing1210 /
Created Feb 12, 2018
Django Template tags to get posts from Facebook, Twitter, Instagram and YouTube.
import urllib
import json
import twitter
from datetime import datetime
from django.conf import settings
from django import template
register = template.Library()
darwing1210 /
Last active Oct 2, 2017
Some useful Django ajax views
class JSONResponseMixin(object):
This is a slightly modified version from django-braces project
content_type = None
json_dumps_kwargs = None
def get_content_type(self): # pragma: no cover
return self.content_type or "application/json"
darwing1210 /
Created May 12, 2017 — forked from jrosebr1/
Validator for files, checking the size, extension and mimetype for Django.
# @brief
# Performs file upload validation for django. The original version implemented
# by dokterbob had some problems with determining the correct mimetype and
# determining the size of the file uploaded (at least within my Django application
# that is).
# @author dokterbob
# @author jrosebr1
import mimetypes
darwing1210 /
Created Feb 11, 2017
Example migraton file to autogerate slug from existing django models
# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2017-02-11 16:54
from __future__ import unicode_literals
from django.db import migrations, models
from django.template.defaultfilters import slugify
def migrate_docs_forward(apps, schema_editor):
documents = apps.get_model("documents", "Documents")
darwing1210 /
Last active Aug 9, 2019
A Python Fabfile to deploy a wordpress site over SSH
import os
from time import time
from fabric.api import sudo, run, task, env, cd, get, local
from fabric.context_managers import shell_env
env.hosts = ['yourhost']
env.user = 'yoursshuser'
env.password = 'yoursshpassword'
# env.key_filename = '~/yourkey.pem'