Skip to content

Instantly share code, notes, and snippets.

View eseiver's full-sized avatar

E. Seiver eseiver

View GitHub Profile
eseiver /
Last active February 10, 2023 02:10
Pywikibot script for updating when a new VOD is released on YouTube
import sys
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
TIMEZONE = ZoneInfo("America/Los_Angeles")
except ZoneInfoNotFoundError:
print("\nTimezone info not found. Please run `pip install tzdata` and try again.\n", file=sys.stderr)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
eseiver /
Last active November 14, 2017 19:23
How to get every PLOS article DOI using PLOS's search API
""" This small script will return a list of every PLOS article DOI.
It uses regular expressions to return only DOIs to full articles.
For more information on text and data-mining PLOS content, see
import requests
def get_all_solr_dois():
Get every article published by PLOS, up to 500,000, as indexed by Solr on
URL includes regex to exclude sub-DOIs and image DOIs.
eseiver /
Last active October 18, 2017 23:02
For renaming annotation articles in existing PLOS XML corpus directory
This renames annotation article files in an existing local copy of corpusdir to fit the new naming scheme.
import os
import re
from plos_corpus import listdir_nohidden, corpusdir
from plos_regex import validate_file
eseiver /
Last active August 28, 2017 22:03
Get all PLOS PMCIDs from PMC using Entrez
import requests
import time
def get_all_pmc_dois(retstart=0, retmax=80000, count=None):
"""Query the entrez database to get a comprehensive list of all PMCIDs associated with all PLOS journals,
individually included in the search url.
See for more info on search parameters
:return: the full list of PMCIDs in PMC for PLOS articles
pmc_allplos_query_url = (''
eseiver /
Created August 22, 2017 20:44
Check the difference between two strings
# With thanks to
# Describes difflib-detected differences in easy-to-understand English
import difflib
cases = [('apple', 'apples'), ('banaana', 'bananas')]
for a, b in cases:
print('{} => {}'.format(a, b))
for i, s in enumerate(difflib.ndiff(a, b)):
eseiver /
Created August 11, 2017 02:37
Functions for downloading files from Google Drive
# With thanks to & @egh
import requests
from tqdm import tqdm
def download_file_from_google_drive(id, destination):
""" General method for downloading from Google Drive.
Doesn't require using API or having credentials
:param id: Google Drive id for file (constant even if filename changes)
:param destination: directory where to download the file
eseiver / Itunes_timecode.applescript
Last active August 2, 2017 03:06
An applescript that returns the timecode position of the current iTunes track. Handy if transcribing or taking notes on an audio file!
tell application "iTunes"
set elapsed_seconds to player position
set this_elapsed_minutes to round elapsed_seconds / 60 rounding down
set N to result
if N < 10 then
set N to 0 & N
end if
set this_elapsed_seconds to elapsed_seconds mod 60
if {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} contains this_elapsed_seconds then
set this_elapsed_seconds to "0" & (this_elapsed_seconds as string)