Interactive tool for creating directed graphs, created using d3.js.
Demo: http://bl.ocks.org/cjrd/6863459
Operation:
- drag/scroll to translate/zoom the graph
| #!/usr/bin/env python3 | |
| import sys, os | |
| def fix_eol(filename): | |
| with open(filename) as f: | |
| contents = f.read() | |
| if not contents.endswith("\n"): | |
| contents += "\n" |
Interactive tool for creating directed graphs, created using d3.js.
Demo: http://bl.ocks.org/cjrd/6863459
Operation:
| def relative_datetime(then): | |
| delta = arrow.now() - then | |
| years, days_of_year = delta.days // 365, delta.days % 365 | |
| months_of_year, days_of_month = days_of_year // 30, days_of_year % 30 | |
| hours_of_day, seconds_of_hour = delta.seconds // (60*60), delta.seconds % (60*60) | |
| minutes_of_hour, seconds_of_minute = seconds_of_hour // 60, seconds_of_hour % 60 | |
| if years != 0: |
| @decorator_with_args | |
| def with_request_values_positionally(view, keys=[], optional_keys=[], | |
| error_view=request_by_json_missing_value): | |
| try: | |
| values = [request.values[key] for key in keys] | |
| #Only catch a KeyError from that particular lookup, not the whole view function | |
| except KeyError: | |
| return error_view() | |
| import sys | |
| from model import Model, NotFound | |
| from tools import get_wikipedia_summary | |
| def safe_print(*args): | |
| try: | |
| print(*args) | |
| except: | |
| pass |
| import requests | |
| from multiprocessing import Pool | |
| from model import Model, NotFound | |
| from mb_api_import import get_album_art_urls | |
| def safe_print(*args): | |
| try: | |
| print(*args) | |
| except: | |
| pass |
| import arrow | |
| from model import Model | |
| def convert_actions(): | |
| with Model() as model: | |
| model.db.executescript( | |
| """drop table if exists actions_2; | |
| create table actions_2 ( | |
| id integer primary key, | |
| user_id integer not null, |
| import sys | |
| from model import Model, NotFound | |
| from tools import get_wikipedia_image | |
| def safe_print(*args): | |
| try: | |
| print(*args) | |
| except: | |
| pass |
| import sys | |
| from model import Model, NotFound | |
| import musicbrainzngs as mb | |
| def mb_get_author_ids(release_mbid): | |
| mb.set_useragent("Skiller", "0.0.0", "[email protected]") | |
| response = mb.get_release_by_id(release_mbid, includes=["artists"])["release"] | |
| return [artist["artist"]["id"] for artist in response["artist-credit"] if isinstance(artist, dict)] |
| def merge_into_release(self, dest_release, src_release): | |
| """Transfers all data from a release to another and removes the source. | |
| Overwrites the destination where the release info differs. | |
| There is never loss of user information.""" | |
| #merge = replace in dest + remove in src | |
| #move = insert in dest + remove in src | |
| def move_actions(model, dest_id, src_id): | |
| model.execute("update actions set object_id=? where object_id=?", src_id, dest_id) |