コード例 #1
0
ファイル: views.py プロジェクト: pombredanne/Lady-Penh
def events(request, date=None):
    today = day = datetime.now().date()
    try:
        reqday = datetime.strptime(date, "%Y-%m-%d").date()
        if request.user.is_authenticated() or (reqday - day).days in range(7):
            day = reqday
    except:
        # just use today date
        pass
    days = helpers.get_days(0)
    daylabels = [(days[0], 'Today'), (days[1], 'Tomorrow')]
    for d in days[2:]:
        daylabels.append((d, d.strftime('%A')))
    article, tags = None, []
    show_edit_links = False
    if request.user.is_authenticated():
        show_edit_links = True
    article,tags=helpers.get_article(today)
    return  render_to_response(request, 'ladypenh/day.html',
                               dict(theme_name=helpers.get_theme(helpers.today()),
                                    day=day,                               
                                    daylabels=daylabels,
                                    highlights=helpers.get_highlights(days),
                                    events=helpers.get_events(day),
                                    reminders=helpers.get_reminders(day),
                                    show_edit_links=show_edit_links,
                                    article=article,
                                    tags=tags
                                    ))
コード例 #2
0
ファイル: main.py プロジェクト: christhorpe/gacscraper
	def get(self, page):
		url = "http://www.gac.culture.gov.uk/search/ObjectSearch.asp?title=&name=&lowdate=0&highdate=0&undated=off&mandm=&group=1279111&order=1&listtype=thumbnail&page=" + page
		results = helpers.get_highlights(url)
		j = 0
		i = 0
		for row in results:
			rowtype = ""
			increment = False
			if "Artist.asp?maker_id=" in str(row):
				j = 0
				work = {}
			if j == 0:
				work["maker_gac_id"] = row["a"]["href"].replace("Artist.asp?maker_id=", "")
				work["maker_name"] = row["a"]["content"].replace("\n", "").replace("                          ", " ").replace("                        ", " ")
				increment = True
			if j == 1 and "COLOR: #" in str(row):
				rowtype = "multiple_artists"
				work["multiple_artists"] = True
			elif j == 1 and "COLOR: #" not in str(row):
				work["multiple_artists"] = False
				work["name"] = row["a"]["content"].replace("\n", "").replace("                                ", " ")				
				increment = True
			if j == 2:
				rowtype = "null"
				increment = True
			if j == 3:
				rowtype = "dates"
				work["dates"] = row["p"].replace("\n", "")
				increment = True
			if j == 4:
				rowtype = "medium"
				work["medium"] = row["p"].replace("\n", "").replace("                        ", " ")
				increment = True
			if j == 5:
				rowtype = "dimensions"
				work["dimensions"] = row["p"].replace("\n", "").replace("                          ", " ")
				increment = True
			if j == 6:
				rowtype = "gac_id"
				increment = True
				work["gac_id"] = row["a"]["href"].replace("Object.asp?object_key=", "")
				self.response.out.write(work)
				self.response.out.write("<br />")
				self.response.out.write("<br />")
				artist = models.Artist.get_or_insert(work["maker_gac_id"], gac_id=work["maker_gac_id"], name=work["maker_name"])
				if not artist.letter:
					if "unknown" in artist.name:
						surname = "unknown"
					else:
						if "(" in artist.name:
							name = artist.name.split("(")[0]
						else:
							name = artist.name.strip() 
						nameelements = name.split(" ")
						surname = nameelements[len(nameelements) - 1]
						if len(surname) == 0:
							surname = nameelements[len(nameelements) - 2]
					letter = surname[0].upper()
					artist.surname = surname
					artist.letter = letter
					artist.put()
				rawdates = work["dates"]
				rawdates = rawdates.replace("c.", "").replace("s", "").replace(" (?)", "").replace("?", "")
				if " " in rawdates:
					dateelements = rawdates.split(" ")
					date = dateelements[len(dateelements) - 1]
				else:
					if "-" in rawdates:
						date = rawdates.split("-")[0]
					elif "/" in rawdates:
						date = rawdates.split("/")[0]				
					else:
						date = rawdates
					#FUDGE!	
					if "22/9/1845-25/9/1845" in rawdates:
						date = "1845"
				try:		
					thiswork = models.Work.get_or_insert(work["gac_id"], artist=artist, gac_id=work["gac_id"], name=work["name"], medium=work["medium"], dates=work["dates"], dimensions=work["dimensions"], multiple_artists=work["multiple_artists"], sortyear=int(date), decade=int(date[0:3] + "0"), century=int(date[0:2] + "00"))
					if not work["gac_id"] in artist.worklist:
						artist.worklist.append(work["gac_id"])
						artist.put()
				except:
					self.response.out.write(str(work) + "<br/>")
			i += 1
			if increment:
				j += 1
			if i == 10:
				taskqueue.add(url="/scrape/highlights/"+ str(int(page) + 1), method="GET")