示例#1
0
def analise_photo_page(link):
    from lxml.etree import tostring

    link = link.replace("http://vk", "http://m.vk")

    print "parsing page " + link

    photo_page_object = make_html_obj_from_link(link, "mobile")

    author_name = photo_page_object.xpath('//div[@class="mv_details"]/dl[2]/dd/a/text()')
    author_name = "" if not author_name else author_name[0]

    author_link = photo_page_object.xpath('//div[@class="mv_details"]/dl[2]/dd/a/@href')
    author_link = "" if not author_link else author_link[0]

    album_name = photo_page_object.xpath('//div[@class="mv_details"]/dl[1]/dd/a/node()')
    album_name = "" if not album_name else album_name[0]

    description = photo_page_object.xpath('//div[@class="mv_description"]/node()')
    title = ""
    if description:
        content = []
        for desc in description:
            if not isinstance(desc, (str, basestring, unicode)):
                content.append(tostring(desc))
            else:
                content.append(desc)
                title += desc

        content = html.escape(" ".join(content))
        title = html.escape(title)
    else:
        content = (
            "Album: " + album_name + ". " + html.escape(photo_page_object.xpath('//div[@class="pv_summary"]/text()')[0])
        )
        title = content

    image_link = photo_page_object.xpath('//li/a[@target="_blank"]/@href')
    if not image_link:
        print link, " has not been parsed correctly"
        print image_link, "\n"
        with open(link.split("/")[-1] + "NotCorrectlyParsedPage.html", "w") as source:
            source.write(tostring(photo_page_object))
        image_link = ""
        photo_hash = ""
    else:
        image_link = image_link[0]
        photo_hash = image_link.split(".")[-2].split("/")[-1]

    from PostParamsContainer import PostParamsContainer

    # page_link='', description='', author_name='', author_link='', image_link='', time='', photo_hash='', content=''
    return PostParamsContainer(
        link, title, author_name, author_link, image_link, photo_hash=photo_hash, content=content
    )
示例#2
0
def log_entry(file_path, request, request_execution_result):
    """
    @type file_path: str
    @type request: jmx_interaction.structures.RequestStructure
    @type request_execution_result: dict
    """
    entry_id = str(random.random() *
                   random.choice([10, 20, 30, 100, 500, 1000, 10000, 100000]))
    diff_operations_div_id = "diffOperations_" + entry_id
    diff_content_table_id = "diffContent_" + entry_id

    file_content = table_entry_top + """<pre id='""" + diff_operations_div_id + """' class ='diffContentTableClass'>
""" + html.escape(request.__str__()) + """</pre>
<pre id='""" + diff_content_table_id + """' style='display: none'>\n
""" + html.escape(str(request_execution_result)) + "</pre>"
    file_content += table_entry_bottom
    write_str_to_file(file_path, file_content)
示例#3
0
 def addMessage(self, message, raw=False):
     if not raw:
         # We assume raw messages, formatted for HTML, are printed separately
         if self.mute: util.unmutePrint()
         print '*** ' + message
         if self.mute: util.mutePrint()
         message = html.escape(message)
     self.messages[self.currentQuestion].append(message)
示例#4
0
def getmapHybrid():
    if session.get('user_id') != None:
        result_df = getCollabRecom(session.get('user_id'))
        mp = folium.Map(location=[36.1699, -115.1398], zoom_start=12)
        for i, r in result_df.iterrows():
            folium.Marker(location=[float(r.latitude),
                                    float(r.longitude)],
                          popup=html.escape(r["business_name"]) + '<br>' +
                          'Stars: ' + str(r.stars) + '<br>' + 'Reviews: ' +
                          str(r.review_count),
                          icon=folium.Icon(color='green')).add_to(mp)
        return mp._repr_html_()
示例#5
0
def _html_interpolate_output_refs(itext_value, context):
    if hasattr(itext_value, 'with_refs'):
        underline_template = '<u>&nbsp;&nbsp;%s&nbsp;&nbsp;</u>'
        return mark_safe(
            itext_value.with_refs(
                context,
                processor=lambda x: underline_template %
                (html.escape(x) if x is not None else
                 '<i class="fa fa-question-circle"></i>'),
                escape=html.escape,
            ))
    else:
        return itext_value
示例#6
0
def getmapNewuser():
    result_df = pd.DataFrame()
    if session.get('keyword') != None:
        result_df = getKeyWordsRecoms(session.get('keyword'), 5).toPandas()
        for key in session.copy():
            session.pop(key, None)
    mp = folium.Map(location=[36.1699, -115.1398], zoom_start=12)
    for i, r in result_df.iterrows():
        folium.Marker(location=[float(r.latitude),
                                float(r.longitude)],
                      popup=html.escape(r["business_name"]) + '<br>' +
                      'Stars: ' + str(r.stars) + '<br>' + 'Reviews: ' +
                      str(r.review_count),
                      icon=folium.Icon(color='green')).add_to(mp)
    return mp._repr_html_()
示例#7
0
def _html_interpolate_output_refs(itext_value, context):
    if hasattr(itext_value, 'with_refs'):
        underline_template = u'<u>&nbsp;&nbsp;%s&nbsp;&nbsp;</u>'
        return mark_safe(
            itext_value.with_refs(
                context,
                processor=lambda x: underline_template % (
                    html.escape(x)
                    if x is not None
                    else u'<i class="icon-question-sign"></i>'
                ),
                escape=html.escape,
            )
        )
    else:
        return itext_value
示例#8
0
def analise_photo_page(link):
    from lxml.etree import tostring

    link = link.replace('http://vk', 'http://m.vk')

    print 'parsing page ' + link

    photo_page_object = make_html_obj_from_link(link, 'mobile')

    author_name = photo_page_object.xpath(
        '//div[@class="mv_details"]/dl[2]/dd/a/text()')
    author_name = '' if not author_name else author_name[0]

    author_link = photo_page_object.xpath(
        '//div[@class="mv_details"]/dl[2]/dd/a/@href')
    author_link = '' if not author_link else author_link[0]

    album_name = photo_page_object.xpath(
        '//div[@class="mv_details"]/dl[1]/dd/a/node()')
    album_name = '' if not album_name else album_name[0]

    description = photo_page_object.xpath(
        '//div[@class="mv_description"]/node()')
    title = ''
    if description:
        content = []
        for desc in description:
            if not isinstance(desc, (str, basestring, unicode)):
                content.append(tostring(desc))
            else:
                content.append(desc)
                title += desc

        content = html.escape(' '.join(content))
        title = html.escape(title)
    else:
        content = 'Album: ' + album_name + '. ' + html.escape(
            photo_page_object.xpath('//div[@class="pv_summary"]/text()')[0])
        title = content

    image_link = photo_page_object.xpath('//li/a[@target="_blank"]/@href')
    if not image_link:
        print link, ' has not been parsed correctly'
        print image_link, '\n'
        with open(link.split('/')[-1] + 'NotCorrectlyParsedPage.html',
                  'w') as source:
            source.write(tostring(photo_page_object))
        image_link = ''
        photo_hash = ''
    else:
        image_link = image_link[0]
        photo_hash = image_link.split('.')[-2].split('/')[-1]

    from PostParamsContainer import PostParamsContainer
    # page_link='', description='', author_name='', author_link='', image_link='', time='', photo_hash='', content=''
    return PostParamsContainer(link,
                               title,
                               author_name,
                               author_link,
                               image_link,
                               photo_hash=photo_hash,
                               content=content)
示例#9
0
        if cmt.exception != '':
            noOfCommitsException += 1

        for ref in cmt.refactorings:
            noOfRefactorings += ref.occurences
            if ref.name.startswith(
                    'Change Parameter Type') or ref.name.startswith(
                        'Change Variable Type') or ref.name.startswith(
                            'Change Return Type') or ref.name.startswith(
                                'Change Attribute Type'):
                noOfTypeChanges += ref.occurences
            descrptions = []
            # print(type(ref.descriptionAndurl))
            for k, v in ref.descriptionAndurl.items():
                descrptions.append(
                    dict(description=html.escape(k), frm=v.lhs, to=v.rhs))

            if descrptions is []:
                refactorings.append(
                    dict(name=ref.name, occurence=ref.occurences, num=0))
            else:
                refactorings.append(
                    dict(name=ref.name,
                         occurence=ref.occurences,
                         descriptions=descrptions,
                         num=len(descrptions)))

        if len(refactorings) > 0 or depChanged:
            pathToCommitsInProject = os.path.join(pathToPages, p.name)
            pathToDetailedCommits = os.path.join(pathToCommitsInProject,
                                                 cmt.sha + ".html")
示例#10
0
def processCode(y):
    el = El("code", html.escape(str(y)))
    el.attr("class", "html")
    return el