Esempio n. 1
0
def populateFATemplate(author, storyAbbreviation, chapterCount):
	url = 'http://www.fictionalley.org/authors/{}/{}.html'.format(
		author, storyAbbreviation
	)
	lastUrl = url[:-5] + '01.html'
	if chapterCount == 1:
		lastUrl = url[:-5] + '01a.html'
	lid = 1

	faRename = {'id': None}
	faDefaults = {
		'fandoms': ['Harry Potter'],
		'characters': [],
		'tags': [],
		'genres': [],
		'authorUrl': 'http://www.fictionalley.org/authors/{}'.format(author),
		'author': author,
		'authorId': author,
		'ageRating': 'PG',
		'language': 'English',
		'favorites': 0,
		'follows': 0,
		'reviews': 0,
		'url': url,
		'lastUrl': lastUrl,
		'type': FicType.fictionalley,
		'lid': lid,
		'ficStatus': Status.complete,
		'wordCount': -1,
		'description': 'FILL IN MY DESCRIPTION',
		'title': 'FILL IN MY TITLE',
		'published': 'FILL IN MY PUBLISHED DATE',
		'updated': 'FILL IN MY UPDATED DATE',
		'added': int(time.time()),
		'fetched': int(time.time())
	}

	fic = Fic.new().__dict__
	fic = inflateObject(fic, faRename, faDefaults)

	fic['chapters'] = {}
	fic['chapterCount'] = chapterCount

	for cid in range(1, chapterCount + 1):
		chapterUrl = url[:-5] + '{:02}.html'.format(cid)
		if chapterCount == 1:
			chapterUrl = url[:-5] + '01a.html'
		fic['chapters'][cid] = {
			'lastModified': int(time.time()),
			'status': Status.ongoing,
			'fetched': int(time.time()),
			'url': chapterUrl
		}
		contentDir = './content/{}/{}/{}'.format(FicType.fictionalley, lid, cid)
		if not os.path.isdir(contentDir):
			os.makedirs(contentDir)

	return fic
Esempio n. 2
0
def importFic(fdata):
	global ficImportRename
	ofic = inflateObject(fdata.copy(), ficImportRename)

	fic = Fic.new()
	for field in ofic:
		print('setting "{}" to "{}"'.format(field, ofic[field]))
		fic.__dict__[field] = ofic[field]

	fic.published = util.parseDateAsUnix(fic.published, int(time.time()))
	fic.updated = util.parseDateAsUnix(fic.updated, int(time.time()))
	print('setting "{}" to "{}"'.format('published', fic.published))
	print('setting "{}" to "{}"'.format('updated', fic.updated))

	print('adding "{}" ({}/{})'.format(fic.title, fic.type, fic.localId))

	fic.insert()

	for fandom in fdata['fandoms']:
		print('  adding fandom "{}"'.format(fandom))
		fic.add(Fandom.define(fandom))
	for character in fdata['characters']:
		print(
			'  adding character "{}" from fandom "{}"'.format(
				character['name'], character['fandom']
			)
		)
		fic.add(
			Character.define(Fandom.define(character['fandom']), character['name'])
		)
	for genre in fdata['genres']:
		print('  adding genre "{}"'.format(genre))
		fic.add(Genre.define(genre))
	for tag in fdata['tags']:
		print('  adding tag "{}"'.format(tag))
		fic.add(Tag.define(tag))

	cids = [int(cid) for cid in fdata['chapters']]
	cids.sort()
	for cid in cids:
		print('  adding chapter {}'.format(cid))
		ochap = fdata['chapters'][str(cid)]
		chapter = FicChapter.new()
		chapter.fic = fic
		chapter.ficId = fic.id
		chapter.chapterId = cid
		for field in ochap:
			chapter.__dict__[field] = ochap[field]
		contentPath = './content/{}/{}/{}/content.html'.format(
			fic.type, fic.localId, cid
		)
		if os.path.isfile(contentPath):
			html = None
			with open(contentPath, 'r') as f:
				html = f.read()
			print('    has content: {}'.format(len(html)))
			chapter.setHtml(html)
		chapter.insert()
Esempio n. 3
0
    def get(self, localId: str) -> Fic:
        existing = Fic.select({'sourceId': self.ftype, 'localId': localId})
        if len(existing) == 1:
            return existing[0]

        fic = Fic.new()
        fic.sourceId = self.ftype
        fic.localId = localId
        fic.created = OilTimestamp.now()
        return self.create(fic)
Esempio n. 4
0
	def getFromZList(self, localId: int, ts: int, html: str) -> Fic:
		fic = None
		existing = Fic.select({'sourceId': self.ftype, 'localId': str(localId)})
		if len(existing) != 1:
			fic = Fic.new()
			fic.sourceId = self.ftype
			fic.localId = str(localId)
			fic.created = OilTimestamp.now()
		else:
			fic = existing[0]
		return self.createFromZList(fic, ts, html)
Esempio n. 5
0
	def get(self, localId: str) -> Fic:
		existing = Fic.select({'sourceId': self.ftype, 'localId': localId})
		if len(existing) == 1:
			return existing[0]
		if not self.cacheable:
			raise Exception('cannot cache {}/{}'.format(localId, self.ftype))

		fic = Fic.new()
		fic.sourceId = self.ftype
		fic.localId = localId
		fic.created = OilTimestamp.now()
		return self.create(fic)
Esempio n. 6
0
def populateManualTemplate(url, chapterUrls, author):
	existingManual = Fic.select({'type': FicType.manual})
	lid = len(existingManual) + 1

	manRename = {'id': None}
	manDefaults = {
		'fandoms': [],
		'characters': [],
		'tags': [],
		'genres': [],
		'authorUrl': url,
		'author': author,
		'authorId': author,
		'ageRating': 'M',
		'language': 'English',
		'favorites': 0,
		'follows': 0,
		'reviews': 0,
		'url': url,
		'lastUrl': url,
		'type': FicType.manual,
		'lid': lid,
		'ficStatus': Status.complete,
		'wordCount': -1,
		'description': 'FILL IN MY DESCRIPTION',
		'title': 'FILL IN MY TITLE',
		'published': 'FILL IN MY PUBLISHED DATE',
		'updated': 'FILL IN MY UPDATED DATE',
		'added': int(time.time()),
		'fetched': int(time.time())
	}

	fic = Fic.new().__dict__
	fic = inflateObject(fic, manRename, manDefaults)

	fic['chapters'] = {}
	fic['chapterCount'] = len(chapterUrls)

	for cid in range(1, len(chapterUrls) + 1):
		fic['chapters'][cid] = {
			'lastModified': int(time.time()),
			'status': Status.ongoing,
			'fetched': int(time.time()),
			'url': chapterUrls[cid - 1],
		}

	return fic