Package: mlseo
mlseoPythonic SEO in JupyterLabInstallpip install mlseo --upgradeHow to useStart a new Notebook, preferably in standalone JupyterLab. Then type:frommlseoimport*Welcome to _                  (\         To chase the rabbit,
  _ __ ___ | |___  ___  ___     \\_ _/(\      run: look()
 | '_ ` _ \| / __|/ _ \/ _ \      0 0 _\)___
 | | | | | | \__ \  __/ (_) |   =(_T_)=     )*
 |_| |_| |_|_|___/\___|\___/      /"/   (  /
           The adventure begins! <_<_/-<__|The Most Important ThingsStoring API Responses into DatabaseThis package contains a variety of building-blocks for constructing "deliverables" for the field of Search Engine Optimization (SEO). The goal is to make expressing such deliverables "light and breezy" by establishing certain conventions. For example, to crawl 1-page of a site into a local database:importhttpxfromsqlitedictimportSqliteDictassqldicturl='https://mikelev.in/'withsqldict('crawl.db')asdb:db[url]=httpx.get(url)db.commit()Using Tuples As Composite-KeysWe are using SQlite as a key-value database in a way that requires the keys to be strings. Keys must be unique so if we use the URL as the key we can store each page we crawl only once. Instead of just a URL, the key to your database can contain a URL and Date so that we can crawl sites on subsequent days and store it into the same key-value database. Such a tuple key looks like this:fromdatetimeimportdateurl='https://mikelev.in/'atuple=(date.today(),url)Pickling and UnpicklingTuples must become strings to be a key in the key-value database we're using. This is accomplished throughpickling. We "pickle" the tuple to make it a string, then can use that string as a key in the dictionary database.importpicklefromdatetimeimportdatepkl=lambdax:pickle.dumps(x)unpkl=lambdax:pickle.loads(x)url='https://mikelev.in/'today=date.today()atuple=(today,url)now_a_string=pkl(atuple)print(now_a_string)Pickling Keys For DatabaseThis example uses a pickled tuple containing the Date and the URL as the database key. It shows data both going in and coming out of the database. Notice the pickled key is restored to its original form. This approach prevents duplicate records in your database. Because dictionary keys must be unique, attempts to insert a new record with the same URL+Date key will fail, meaning this crawler can only record each page on the site once per day.importhttpximportpicklefromdatetimeimportdatefromsqlitedictimportSqliteDictassqldictpkl=lambdax:pickle.dumps(x)unpkl=lambdax:pickle.loads(x)url='https://mikelev.in/'# Data goes inwithsqldict('crawl.db')asdb:tupkey=(date.today(),url)db[pkl(tupkey)]=httpx.get(url)db.commit()# Data comes outwithsqldict('crawl.db')asdb:fortupkeyindb:adate,url=unpkl(tupkey)print(adate,url)mlseo TutorialsHOUSEKEEPING:Once you have the basic trick of using a persistent dictionary and using tuples as your primary key, you'll need a place toputthe database and all your other INPUT/OUTPUT files besides lumping it all into the top-level of your folder.A Word About JupyterLabRecovering pip installsFor now standalone Jupyter has to be reinstalled a lot and its easy to lose your pip-installed packages. For mlseo you can get all the necessary packages back by just typing this into a Code cell:pip install mlseo --upgradeUseful Dev ToolsI also recommend installing nbdev and nb_black if you're doing any development work inside Jupyter:pip install nb_black
pip install nbdevRestart Kernel & Clear All Outputs A LOTAnd lastly, shortcuts always get deleted between Jupyter reinstalls so here's my most important shortcut. It's always a good time to Restart kernel and clear all outputs.{"shortcuts":[{"command":"kernelmenu:restart-and-clear","keys":["Ctrl Shift R"],"selector":"body"}]}