Example #1
0
def favorite(session, mango_url):
    res = session.get(mango_url)
    soup = BeautifulSoup(res.content, "html.parser")

    fav = soup.find("span", {"class": "text"}).text.lower()
    html = res.text
    tk_start = html.index("csrf_token: \"")
    #13 to account for the csrf_token: "
    html = html[tk_start + 13:]
    token = html[:html.index("\"")]

    mango_id = mango_url.split("/")[-2]
    post_url = base_url + "/api/gallery/" + mango_id + "/" + fav

    res = session.post(post_url,
                       headers={
                           "referer": mango_url,
                           "x-csrftoken": token,
                           "x-requested-with": "XMLHttpRequest"
                       })

    if res.ok:
        fav = soup.find("span", {"class": "text"}).text
        return mango_url + " has been " + ("favorited" if fav == "Favorite"
                                           else "unfavorited")
Example #2
0
def getRelatedVideos(html):
  end = 0
  while True:
    start = html.find('video-list-item related-list-item', end)
    if start == -1: break
    (start, end) = search(html, 'href="', '"', start)
    start = html.index('v=', start) + len('v=')
    amp_idx = html.find('&', start, end)
    if amp_idx != -1: end = amp_idx
    yield html[start:end]
Example #3
0
    def servePage(self, path):
        import html, re
        subdirlist = re.split('/', path)

        if not subdirlist[1]:
            return html.index('\'root\'')

        elif subdirlist[1] == 'hello':

            if len(subdirlist) > 2:
                if re.search('([0-9]|[a-zA-Z])*', subdirlist[2]):

                    return html.index('Hello ' + subdirlist[2])
                else:
                    return html.index('not a valid')
            else:
                return html.index('hello world')

        elif subdirlist[1] == 'ola':

            return html.index('ola mundo')

        else:

            return html.index('not a valid')
def getXGitlabID(url):
    global xGitDict
    url_split = url.split('/')
    base_url = url_split[0] + "//" + url_split[2] + "/" + url_split[
        3] + "/" + url_split[4]
    #Cache the id so we don't have to download the page for every file
    if base_url in xGitDict:
        return xGitDict[base_url]
    gid = "Unknown"
    pidStr = "Project ID: "
    response = requests.get(base_url)
    html = response.content.decode("utf-8")
    if not pidStr in html:
        xGitDict[base_url] = gid
        return gid
    piddex = html.index(pidStr) + len(pidStr)
    enddex = html.index("\n", piddex)
    gid = html[piddex:enddex]
    quotDex = gid.find("\"")
    if quotDex > -1:
        gid = gid[0:quotDex]
    #print("XGIT-ID: ",gid)
    xGitDict[base_url] = gid
    return gid
Example #5
0
    def __init__(self, model):
        """Initialise the process object        
                
        :param model: The UI model for all entered data.
        :type model: d3MapRenderer.logic.model
        """
        self.__logger = log(self.__class__.__name__)
        self.__colorField = "d3Css"
        self.__sizeField = "d3S"
        self.__cssFile = "color.css"

        self.__qgis = qgisWrapper()
        self.osHelp = osHelper()
        self.model = model
        self.htmlWriter = index()
Example #6
0
def create_index(book, connection):
    doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n'
    style = html.Element('<style>', 'ul {list-style-type: none; text-align:center;}')
    index = html.Element('<html>', str(html.header('Address Book', style) + str(html.index(book))))
    connection.sendall(doctype + str(index))
Example #7
0
File: build.py Project: BYU-SE/idb
# Next we query the just built database to create a static website in the 'html' directory (creating that directory in the process, if needed)

html_dir = 'docs'
incidents_dir = html_dir + '/incidents'

for d in [html_dir, incidents_dir]:
    if not os.path.exists(d):
        os.makedirs(d)

incidents = db.incidents()

#
# Create an index.html file listing all incidents

with open(html_dir + '/index.html', 'w', encoding='utf8') as file:
    file.write(html.index(incidents))

#
# Create an html index file listing all incidents by the year the incident happened in

incidents_by_year = []
for year in db.years():
    incidents_by_year.append(
        (year, [i for i in incidents if i.year() == year]))

with open(html_dir + '/years.html', 'w') as file:
    file.write(html.categorized_index(incidents_by_year, "Years"))

#
# Create an html index file listing all incidents by the organization that had the incident
Example #8
0
def getTTSURL(html):
  start = html.index('"ttsurl"') + len('"ttsurl"')
  (start, end) = search(html, '"', '"', start)
  return html[start:end].replace('\/', '/').replace('\\u0026', '&')