inpX
: must be a bs4 document/tag/ResultSet or a string or a list of strings- ( target variable must be JSON and seaparated from other variables by
;
)
- ( target variable must be JSON and seaparated from other variables by
varName
: name of the target variable- ( only the first variable found with the specified name will be returned )
selector
: a CSS selector for searching the bs4 document/tag for target script- ( if inpX is a script-tag/ResultSet/string/list then selector doesn't matter )
prepFn
: should be a univariate function that takes a string and returns a string- ( for modifying the script string before searching for and parsing variable )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Variables + zone & region | |
YOUR_REGION = "" # scenario europe-west1 | |
YOUR_ZONE = "" #scenario europe-west1-b | |
INSTANCE_NAME = "" #task1 nucleus-jumphost-640 | |
CLUSTER_NAME = "" #task2 [nucleus-backend] [not provided - made up] | |
APP_PORT_NUMBER = "" #task2 8080 | |
FIREWALL_RULE = "" #task3 accept-tcp-rule-846 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date, datetime, timedelta | |
def get_midpoint(sd:date, ed:date, eod=True, is_v:bool=True, toRet=None): | |
# Calculate the midpoint | |
start_date = datetime(sd.year, sd.month, sd.day, | |
23 if eod else 0, 59 if eod else 0) | |
end_date = datetime(ed.year, ed.month, ed.day, 0, 1 if eod else 0) | |
total_duration = (end_date - start_date).total_seconds() | |
half_duration = total_duration // 2 # integer quotient | |
midpoint_dt = start_date + timedelta(seconds=half_duration) |
This gist contains a Python tool for converting flat HTML documents—especially those with nested content indicated only by header levels (like <h1>
, <h2>
, etc.)—into a structured JSON object that reflects the implicit hierarchy.
Originally inspired by this StackOverflow question from @psychicesp, this script is useful for:
- Web scraping content-heavy pages (like menus, outlines, legal docs)
- Explicitly inferring structure from heading levels
- Preserving content hierarchy when working with markdown-to-HTML output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def yield_key_paths(objC, valT, kPath=None, validTypes=(tuple,list,dict,set)): | |
''' Traverse objC data structure recursively to yield path/s to valT''' | |
if not isinstance(kPath, list): kPath = [] | |
if objC == valT: yield kPath | |
if not isinstance(objC, validTypes): return | |
for k,v in (objC.items() if isinstance(objC,dict) else enumerate(objC)): | |
yield from yield_key_paths(v, valT, kPath+[k], validTypes) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## [ specifying data type of value with dType is optional ] | |
# a generator for the values | |
def yield_by_nested_keys(obj:dict, *keys, dType=None): | |
if not keys or not isinstance(obj,(dict,list,set,tuple)): return | |
if not isinstance(obj, dict): | |
for v in obj: | |
for y in yield_by_nested_keys(v,*keys,dType=dType): yield y | |
return | |
if len(keys)==1 and keys[0] in obj: | |
if dType is None or isinstance(obj[keys[0]], dType): |
View the notebook on Google Colab (if you want to run the code interactively).
This project contains an experimental scraper and data processing notebook for building practice tools for the TCF Canada exam, focusing on Expression Orale and Expression Écrite tasks.
- Goal: Collect, organize, and categorize prompts for TCF Canada speaking and writing practice.
- Use Case: Forms the foundation for a web app or study aid that randomizes practice tasks and ensures coverage across different categories.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.