Skip to content

Instantly share code, notes, and snippets.

@gpirrotta
gpirrotta / gitdiff.py
Last active October 16, 2022 05:49
Git Diff Visualcad
import json
import csv
f = open('../data/data_cad.json')
rows = json.load(f)
previous_article = {}
with open('../data/gitdiff.csv', mode='w') as csv_file:
fieldnames = ['data', 'articolo', 'type','no','size_article']
@gpirrotta
gpirrotta / opendatazen.py
Last active October 16, 2022 05:40
OpenDataZen, data sonification del CAD
import pandas as pd
from pydub import AudioSegment
rain = AudioSegment.from_file("../sounds/rain_background.wav", format="wav")
wind = AudioSegment.from_file("../sounds/wind.mp3", format="mp3")
thunder = AudioSegment.from_file("../sounds/thunder.wav", format="wav")
bird = AudioSegment.from_file("../sounds/bird.mp3", format="mp3")
df=pd.read_csv('../data/gitdiff.csv')
@gpirrotta
gpirrotta / violin.py
Last active October 15, 2022 17:17
Violin-piano data sonification
from music21 import converter,instrument
s = converter.parse('../sounds/cad-piano.mid')
for p in s.parts:
p.insert(0, instrument.Violin())
s.write('midi', '../sounds/cad-violino.mid')
@gpirrotta
gpirrotta / piano.py
Last active October 15, 2022 17:15
CAD-Piano data sonification
import partitura.score as score
import partitura
import pandas as pd
part = score.Part('P0', 'Piano', quarter_duration=1250)
source =pd.read_csv('../data/gitdiff.csv')
first_song = source[source['data']=='2005-03-07']
len_song = first_song.shape[0]
half_len = int(len_song/2)
@gpirrotta
gpirrotta / carbon_calculator_output.json
Created December 11, 2021 10:34
Carbon Calculator JSON OUTPUT
{
"date": "2021-12-10T16:07:20.881173+01:00",
"url": "https://www.unime.it",
"hosting_green": false,
"co2_grams": 2.3048954692203547,
"energy_kWh": 0.004852411514148116,
"water_litres": 1.2819828599803613,
"resources": {
"transfer_size_bytes": {
"total": 3823256,
@gpirrotta
gpirrotta / config.ini
Created December 11, 2021 09:24
Esempio di config.ini file:
[GREENWEB]
GREENWEB_PATH = /Users/giovanni/projects/carbon-calculator/data/green_urls.db
[LIGHTHOUSE]
LIGHTHOUSE_PATH = /Users/giovanni/.nvm/versions/node/v14.17.6/bin/lighthouse
@gpirrotta
gpirrotta / carbon_calculator_cli
Last active December 11, 2021 10:31
Carbon Calculator CLI
carbon-cli -h
usage: carbon-cli [-h] -db GREENWEB [-lh LIGHTHOUSE] website
Carbon Calculator - the tool calculates the carbon emissions (CO2) and green infos of any website
positional arguments:
website The URL to analyze
optional arguments:
@gpirrotta
gpirrotta / carbon_calculator_library_from_ini.py
Last active December 27, 2021 09:45
Using Carbon Calculator from INI File
from carbon.calculator import CarbonCalculator
carbon = CarbonCalculator.from_ini_file('config.ini')
carbon.footprint("https://www.unime.it")
print(carbon.co2_grams)
//0.29566587414592505
@gpirrotta
gpirrotta / carbon_calculator_library.py
Last active December 11, 2021 10:11
Using Carbon Calculator as python library
from carbon.calculator import CarbonCalculator
from carbon.services import LighthouseService, GreenWebService
# If lighthouse tool is installed globally the following row can be omitted
lighthouse = LighthouseService(lighthouse = PATH_OF_LIGHTHOUSE_TOOL)
# It loads the Green Web Dataset DB (must be a SQL3Lite file)
greenweb = GreenWebService(greenweb = PATH_OF_GREEN_DB)
# It calculates CO2 emissions
█▄▄ █░█ █▀▄▀█ █▀█ ▄▄ █░█ █▀▀ █▀█ █▀ █ █▀█ █▄░█
█▄█ █▄█ █░▀░█ █▀▀ ░░ ▀▄▀ ██▄ █▀▄ ▄█ █ █▄█ █░▀█
                                        v0.1.0

Description:

This script automates bumping the git software project's version using automation.

It does several things that are typically required for releasing a Git repository, like git tagging, automatic updating of CHANGELOG.md, and incrementing the version number in various JSON files: