Пример #1
0
def grab(channel, timespan):
    tz = pytz.timezone("Europe/Athens")
    now = datetime.datetime.now(tz)
    charset = "windows-1253"
    shows = []
    a = 0
    if now.time().hour < 7:
        a = -1
    for i in range(a, 14):
        date = now + datetime.timedelta(days=i)
        text = helper.download("https://program.ert.gr/Ert1/index.asp?id=" +
                               channel + "&pdate=" + date.strftime("%d/%m/%Y"),
                               encoding=charset)
        if text is None:
            continue

        sections = helper.split(
            text, "<td width=\"50\" align=\"center\" class=\"table\">",
            "</tr></table>")
        laststart = datetime.datetime.min.replace(tzinfo=tz)
        for section in sections:
            show = {}

            temp = re.search("(\d\d):(\d\d)", section)
            show["start"] = date.replace(hour=int(temp.group(1)),
                                         minute=int(temp.group(2)),
                                         second=0,
                                         microsecond=0)
            if show["start"] < laststart:
                date += datetime.timedelta(days=1)
                show["start"] += datetime.timedelta(days=1)

            if (show["start"] - now).total_seconds() / 3600 > timespan:
                lastshow = True
            else:
                lastshow = False

            laststart = show["start"]

            temp = re.search("<a class=\"black\".*href=\"(.*)\">(.*)</a>",
                             section)

            show["title"] = temp.group(2)

            subtitle = helper.cut(
                section, "<td width=\"3\"></td><td><font color=\"#6e6868\">",
                "</font>")
            if subtitle is not None and subtitle:
                show["sub-title"] = subtitle

            link = temp.group(1)
            if link[0] == "/":
                link = "https://program.ert.gr" + link
            if link:
                show["details-url"] = link

            shows.append(show)
            if lastshow:
                return shows
    return shows
Пример #2
0
def grabdetails(url):
	text = helper.download(url)
	if text is None:
		return None
	show = {}
	subtitle = helper.cut(text, "<h3 class=\"overlay-subtitle\">", "</h3>")
	if subtitle is not None and subtitle:
		show["sub-title"] = helper.cleanup(subtitle)

	description = helper.cut(text, "<p class=\"overlay-text\">", "</p>")
	if description is not None and description:
		show["desc"] = helper.cleanup(description)

	if text.find("Untertitel für Hörgeschädigte") != -1:
		show["subtitles"] = True
	return show
Пример #3
0
def grab(channel, timespan):
	tz = pytz.timezone("Europe/Berlin")
	now = datetime.datetime.now(tz)
	shows = []
	a = 0
	if now.time().hour < 7:
		a = -1

	for i in range(a, 14):
		date = now + datetime.timedelta(days=i)
		text = helper.download("http://www.zdf.de/live-tv?airtimeDate=" + date.strftime("%Y-%m-%d"))
		if text is None:
			continue

		text = helper.cut(text, "<section class=\"b-epg-timeline timeline-" + channel, "</section>")

		sections = helper.split(text, "<li", "</li>")
		laststart = datetime.datetime.min.replace(tzinfo=tz)
		for section in sections:
			show = {}

			temp = helper.cut(section, "<span class=\"time\">", "</span>")
			temp = re.search("(\d\d):(\d\d) - (\d\d):(\d\d)", temp)	
			show["start"] = date.replace(hour=int(temp.group(1)), minute=int(temp.group(2)), second=0, microsecond=0)
			if show["start"] < laststart:
				date += datetime.timedelta(days=1)
				show["start"] += datetime.timedelta(days=1)

			if (show["start"] - now).total_seconds() / 3600 > timespan:
				return shows

			laststart = show["start"]
			show["stop"] = date.replace(hour=int(temp.group(3)), minute=int(temp.group(4)), second=0, microsecond=0)
			if show["stop"] < show["start"]:
				show["stop"] += datetime.timedelta(days=1)
			temp = re.search("<span class=\"overlay-link-category\">(.*?)<span class=\"visuallyhidden\">:</span></span>\s*(?:<.*>)*\s*(.*?)\s*?</a>", section)
			if temp.group(1):
				show["title"] = helper.cleanup(temp.group(1) + " - " + temp.group(2))
			else:
				show["title"] = helper.cleanup(temp.group(2))

			temp = re.search("contentUrl\": \"(.*)\"", section)
			if temp is not None:
				show["details-url"] = "http://www.zdf.de" + temp.group(1)

			shows.append(show)
	return shows
Пример #4
0
def grabdetails(url):
	text = helper.download(url)
	if text is None:
		return None
	show = {}
	description = helper.cut(text, "<meta name=\"description\" content=\"", "\" />")
	if description is not None:
		show["desc"] = helper.cleanup(description)
	return show
Пример #5
0
def grab(channel, timespan):
    tz = pytz.timezone("Europe/Athens")
    now = datetime.datetime.now(tz)
    shows = []
    a = 0
    if now.time().hour < 4:
        a = -1
    for i in range(a, 6):
        date = now + datetime.timedelta(days=i)
        text = helper.download(
            "http://ishow.gr/showTodayChannelProgramm.asp?cid=" + channel +
            "&gotoDay=" + str(i))
        if text is None:
            continue

        sections = helper.split(text, "<tr id=\"progTr", "</tr>")
        laststart = datetime.datetime.min.replace(tzinfo=tz)
        for section in sections:
            show = {}

            temp = re.search(
                "<td class=\"progTd progTdTime\".*?>(\d\d):(\d\d)", section)
            show["start"] = date.replace(hour=int(temp.group(1)),
                                         minute=int(temp.group(2)),
                                         second=0,
                                         microsecond=0)
            if show["start"] < laststart:
                date += datetime.timedelta(days=1)
                show["start"] += datetime.timedelta(days=1)

            if (show["start"] - now).total_seconds() / 3600 > timespan:
                lastshow = True
            else:
                lastshow = False

            laststart = show["start"]

            title = re.search("<div class=\"grandTitle\".*>(.+)\s*?</div>",
                              section)
            show["title"] = helper.cleanup(title.group(1))

            subtitle = helper.cut(section, "<div class=\"subTitle\">",
                                  "</div>")
            if subtitle is not None and subtitle:
                show["sub-title"] = helper.cleanup(subtitle)

            temp = re.search("<div class=\"grandTitle\">.*?href=\"(.*?)\"",
                             section)
            if temp is not None:
                show["details-url"] = "http://ishow.gr" + temp.group(1)

            shows.append(show)
            if lastshow:
                return shows
    return shows
Пример #6
0
def labellizeImage(filePath, savePath, nbFrag, client):
    image = getImage(filePath)
    labels = []

    for n in range(1, nbFrag):
        fragments = cut(image, n)
        #print("Image découpée en " + str((n+1)*(n+1)))

        w, h = image.size
        dw = w / n
        dh = h / n
        x = y = 0
        for fragment in fragments:
            newLabels = labellize(fragment, client)

            for label in newLabels:
                vertices = label.bounding_poly.normalized_vertices
                for vertex in vertices:
                    vertex.x += x
                    vertex.y += y
            y += dh
            if y >= h:
                y = 0
                x += dw

            labels.extend(newLabels)


#		print("Fragments labellisés, " + str(len(labels)) + " labels")
#	lbls = []

#	for label in labels:
#		lbls.append(Label(label.name, label.bounding_poly, label.score))

#	labels = connectLabels(labels)
#	print("Fragements connectés : " + str(len(labels)) + " fragments restants")
#print (json.dumps(lbls))
#	text = jsonpickle.encode(labels[0])
#	print(text)
#print(dir(labels[0]))
    drawn = drawImage(image, labels)
    #print("Image dessinée")

    saveImage(drawn, savePath)
    json = listToJson(labels)
    savePath = savePath[:-4]
    savePath += ".json"
    with open(savePath, 'w') as file:
        file.write(json)
Пример #7
0
def grabdetails(url):
    text = helper.download(url)
    if text is None:
        return None
    show = {}
    description = helper.cut(text,
                             "<meta property=\"og:description\" content=\"",
                             "/>")
    temp = re.search(
        "<meta property=\"og:description\" content=\"(.*?)(?:\"/>|<)", text)
    if temp is not None:
        description = temp.group(1)
        if description:
            show["desc"] = helper.cleanup(description)
    return show
Пример #8
0
def grab(channel, timespan):
    tz = pytz.timezone("UTC")
    now = datetime.datetime.now(tz)
    shows = []

    laststart = datetime.datetime.min.replace(tzinfo=tz)
    for i in range(1 + timespan // 4):
        timestamp = int(time.time()) + i * 14400
        text = helper.download("https://www.dw.com/epg/data/4765/1/" +
                               str(timestamp) + "000")
        if text is None:
            continue

        channeldata = helper.cut(text, "data-channel-id=\"" + channel + "\"",
                                 "data-channel-id")
        if not channeldata:
            try:
                channeldata = text.split("data-channel-id=\"" + channel +
                                         "\"")[1]
            except IndexError:
                continue
        sections = helper.split(channeldata, "<div class=\"epgProgram\"",
                                "<div class=\"broadcastlinks\">")

        for section in sections:
            show = {}
            day = helper.cut(section, "data-day=\"", "\"")
            begintime = helper.cut(section, "data-begin-time=\"", "\"")
            endtime = helper.cut(section, "data-end-time=\"", "\"")

            show["start"] = pytz.utc.localize(
                datetime.datetime.strptime(day + begintime, "%Y-%m-%d%H:%M"))
            if show["start"] <= laststart:
                continue
            if (show["start"] - now).total_seconds() / 3600 > timespan:
                return shows
            laststart = show["start"]

            show["stop"] = pytz.utc.localize(
                datetime.datetime.strptime(day + endtime, "%Y-%m-%d%H:%M"))
            if show["stop"] < show["start"]:
                show["stop"] += datetime.timedelta(days=1)

            show["title"] = helper.cleanup(
                helper.cut(section, "<h2 class=\"title\">", "</h2>"))
            url = helper.cut(section, "<a href=\"", "\">")
            if url is not None and url:
                show["url"] = "https://www.dw.com" + url
            description = helper.cleanup(
                helper.cut(section, "<ul class=\"topics\">", "</ul>"))
            if description is not None and description:
                show["desc"] = description

            try:
                icon = re.search("<img[\s\S]*?/>", section).group(0)
                width = helper.cut(icon, "width=\"", "\"")
                height = helper.cut(icon, "height=\"", "\"")
                src = "https://www.dw.com" + helper.cut(icon, "src=\"", "\"")
                show["icon"] = (src, {"width": width, "height": height})
            except (AttributeError, IndexError):
                pass

            shows.append(show)
    return shows