Skip to content

Instantly share code, notes, and snippets.

View javierwilson's full-sized avatar

javier wilson javierwilson

  • Managua, Nicaragua
View GitHub Profile
@javierwilson
javierwilson / match-per-xtime.py
Created July 24, 2022 07:31
counts matches per X time
!/usr/bin/python3
import fileinput
from datetime import datetime, date, timedelta
from collections import OrderedDict
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-s", "--step", default='minutes', help="group by seconds, minutes or hours")
parser.add_argument('files', metavar='FILE', nargs='*', help='files to read, if empty, stdin is used')
@javierwilson
javierwilson / check2event.sh
Last active June 3, 2020 06:03
Runs check, sends output to events API
#!/bin/bash
rootdir="/usr/local/bin/checks"
checkfile=${1//[^a-zA-Z0-9_]/}
checkfile="${rootdir}/$checkfile"
checkname=${1//[^a-zA-Z0-9_]/}
if [ $# -lt 2 ]; then
echo "Usage:"
script=`basename "$0"`
echo "${script} <check_script> <check_name> [arg1] [arg2] [argN]"
exit 1
SELECT project.code AS project_id,
subproject.code AS subproject_id,
project.recordtype,
project.atype AS type,
lwrregion.NAME AS region,
lwrregion2.NAME AS region2,
Getprojectcountries(project.id) AS countries,
country2.NAME AS country,
COALESCE(agriculture, 0) AS agriculture,
agriculture_count,
@javierwilson
javierwilson / check-btn.py
Last active April 29, 2020 13:37
Check ByTheNumbers records for strange things
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import codecs
import sys
from simple_salesforce import Salesforce
import secrets
UTF8Writer = codecs.getwriter('utf8')
sys.stdout = UTF8Writer(sys.stdout)
@javierwilson
javierwilson / commcare_macpsos2lac.py
Created April 22, 2019 15:41
Convierte commcare export a Excel compatible con sistema LAC
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pandas as pd
commcare_data = pd.read_excel("commcare.xlsx", header=0)
lac_data = pd.read_excel("lac.xlsx", sheet_name="BENEFICIARIO", header=1)
for index, commcare_row in commcare_data.iterrows():
if commcare_row["form.dui"] in lac_data[u"Número de Identificación"]:
print commcare_row["form.dui"]
lac_row = pd.DataFrame({
u"Nombre de Proyecto":["SOS"],
@javierwilson
javierwilson / fake-data.py
Created February 26, 2019 21:46
Create Fake CSV data
#!/usr/bin/python
import csv
import copy
import random
def play(datum, min=1, max=25):
if datum == '':
return 0
else:
@javierwilson
javierwilson / backup_remote_mail.sh
Created December 7, 2018 15:06
Backing up Cyrus mail server database
#!/bin/bash
DEST=/backup1/example/mail/spool/
TEST=/backup1/BACKUP.txt
if [ ! -f $TEST ]; then
echo "Backup disk not mounted!"
exit
fi
projects = sf.query_all("SELECT Id, Name, Project_Identifier__c, Project_Type__c, LWR_Region__c, Start_Date__c, End_Date__c FROM Project__c WHERE RecordTypeId <> '0120Z0000016F8q' AND End_Date__c >= 2017-09-30")
i = 1
objs = ['Agriculture__c', 'Climate_Change__c', 'Constituent_Engagement__c', 'Emergency_Operations__c', 'Civic_Participation__c', 'Health_Livelihood__c', 'Water__c', 'Other__c']
objs_string = ",".join(objs)
print "Number,Id,Project_Identifier__c,Project_Type__c,LWR_Region__c,Start_Date__c,End_Date__c,Name,%s" % (objs_string)
for item in projects['records']:
subs = sf.query_all("SELECT Id, %s FROM Sub_Project__c WHERE Project__r.Id='%s'" % (objs_string, item['Id']))
data = {}
for o in objs:
#!/usr/bin/env python
from simple_salesforce import Salesforce
import pprint
pp = pprint.PrettyPrinter(depth=6)
token = 'token'
username = 'bob@example.com'
password = 'password'
@javierwilson
javierwilson / report.py
Created August 24, 2017 11:21 — forked from snopoke/report.py
Generates CSV for last week cpu, mem and disk utilization
#!/usr/bin/env python
import datetime
import os
from datadog import initialize, api
from collections import defaultdict
options = {