Skip to content

Instantly share code, notes, and snippets.

@BlogBlocks
Last active December 19, 2017 00:39
Show Gist options
  • Select an option

  • Save BlogBlocks/6a998d1fc27e2a85446590fb31e4629a to your computer and use it in GitHub Desktop.

Select an option

Save BlogBlocks/6a998d1fc27e2a85446590fb31e4629a to your computer and use it in GitHub Desktop.
"""Creates a name based on a url:
USAGE:
URL_local = "News---Somali-hijackings-after-five-year-lull_icc-ccs.org_.html"
Ntitle(URL_local)
If used as a module:
import Beautihelp
Beautihelp.Ntitle(URL_local)
"""
def Ntitle(URL_local, exten = -5, length= -17, NewExt = ".txt"):
#removes the period
txt = URL_local.replace(".","_")
#removes the extension 'exten' (Default: exten = -5 )
txt = txt[:exten]
#removes all front characters keeping the last 'length' (Default: length= -17)
txt = txt[length:]
#Adds a ".txt" extension
txt = txt+NewExt
return txt
#URL_local = "News---Maritime-piracy-report-sees-first-Somali-hijackings-after-five-year-lull_icc-ccs.org_.html"
# Ntitle(URL_local)
# prints: lull_icc-ccs_org_.txt
# print Ntitle(URL_local, exten = -6, length=-11)
# prints: icc-ccs_org.txt
@BlogBlocks

Copy link
Copy Markdown
Author

made public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment