예제 #1
0
def getPaymentDictionary(round):
	'Get the payment dictionary.'
	addressDictionary = account.getAddressDictionary(round)
	paymentDictionary = {}
	lines = almoner.getTextLines(almoner.getFileText('receiver_%s.csv' % round))
	isAddressSection = False
	addressLines = []
	for line in lines[: 4000]:
		firstWord = ''
		line = line.strip()
		words = line.split(',')
		if len(words) > 0:
			firstWord = words[0].strip()
		if firstWord == '_endcoins':
			isAddressSection = False
		if isAddressSection and len(line) > 0:
				addressLines.append(line)
		if firstWord == '_begincoins':
			isAddressSection = True
	addressLines += addressLines * (4000 / len(addressLines))
	for addressLine in addressLines[: 4000]:
		payment = 45000.0 / float(len(words))
		words = addressLine.split(',')
		for word in words:
			name = addressDictionary[word].lower()
			if name in paymentDictionary:
				paymentDictionary[name] += payment
			else:
				paymentDictionary[name] = payment
	return paymentDictionary
예제 #2
0
def writeOutput(arguments):
    'Write output.'
    if '-h' in arguments or '-help' in arguments:
        print(__doc__)
        return
    round = int(almoner.getParameter(arguments, '23', 'round'))
    rootFileName = almoner.getParameter(arguments, 'devtome', 'wiki')
    currentFileName = almoner.getParameter(arguments,
                                           rootFileName + '_%s.csv' % round,
                                           'current')
    previousFileName = almoner.getParameter(
        arguments, rootFileName + '_%s.csv' % (round - 1), 'previous')
    lines = almoner.getTextLines(almoner.getFileText(previousFileName))
    titleLine = lines[0]
    titles = titleLine.split(',')
    backupFolder = rootFileName + '_articles'
    authors = getAuthors(backupFolder, lines, titles)
    totalTomecount = getTotalTomecount(authors)
    tomecountText = getTomecountText(authors, totalTomecount)
    earningsText = getEarningsText(authors)
    outputSummaryTo = almoner.getParameter(arguments, 'devtome_summary.txt',
                                           'summary')
    almoner.writeFileText(currentFileName, tomecountText)
    outputEarningsTo = almoner.getParameter(arguments,
                                            'devtome_earnings_%s.csv' % round,
                                            'earnings')
    if almoner.sendOutputTo(outputEarningsTo, earningsText):
        print('The devtome earnings file has been written to:\n%s\n' %
              outputEarningsTo)
    if almoner.sendOutputTo(
            outputSummaryTo, getSummaryText(earningsText, round,
                                            totalTomecount)):
        print('The summary file has been written to:\n%s\n' % outputSummaryTo)
예제 #3
0
def writeOutput(arguments):
	'Write output.'
	if '-h' in arguments or '-help' in arguments:
		print(__doc__)
		return
	round = int(almoner.getParameter(arguments, '23', 'round'))
	rootFileName = almoner.getParameter(arguments, 'devtome', 'wiki')
	currentFileName = almoner.getParameter(arguments, rootFileName + '_%s.csv' % round, 'current')
	previousFileName = almoner.getParameter(arguments, rootFileName + '_%s.csv' % (round - 1), 'previous')
	viewFileName = almoner.getParameter(arguments, 'devtome_analytics_%s.csv' % round, 'view')
	lines = almoner.getTextLines(almoner.getFileText(previousFileName))
	titleLine = lines[0]
	titles = titleLine.split(',')
	backupFolder = rootFileName + '_articles'
	viewDictionary = getViewDictionary(viewFileName)
	authors = getAuthors(backupFolder, lines, titles, viewDictionary)
	totalTomecount = getTotalTomecount(authors)
	tomecountText = getTomecountText(authors, totalTomecount)
	earningsText = getEarningsText(authors)
	outputSummaryTo = almoner.getParameter(arguments, 'devtome_summary.txt', 'summary')
	almoner.writeFileText(currentFileName, tomecountText)
	outputEarningsTo = almoner.getParameter(arguments, 'devtome_earnings_%s.csv' % round, 'earnings')
	if almoner.sendOutputTo(outputEarningsTo, earningsText):
		print('The devtome earnings file has been written to:\n%s\n' % outputEarningsTo)
	if almoner.sendOutputTo(outputSummaryTo, getSummaryText(earningsText, round, totalTomecount)):
		print('The summary file has been written to:\n%s\n' % outputSummaryTo)
예제 #4
0
def getViewDictionary(viewFileName):
	'Get the page view dictionary.'
	viewDictionary = {}
	lines = almoner.getTextLines(almoner.getFileText(viewFileName))
	for line in lines[1 :]:
		words = line.split(',')
		if len(words) > 1:
			viewDictionary[words[0]] = words[1]
	return viewDictionary
예제 #5
0
def getViewDictionary(viewFileName):
    'Get the page view dictionary.'
    viewDictionary = {}
    lines = almoner.getTextLines(almoner.getFileText(viewFileName))
    for line in lines[1:]:
        words = line.split(',')
        if len(words) > 1:
            viewDictionary[words[0]] = int(words[1])
    return viewDictionary
예제 #6
0
def getRecentTitles(archiveType, fileNameRoot, wikiAddress):
	'Get all titles of the dokuwiki.'
	archiveFileName = fileNameRoot + '.' + archiveType
	if not os.path.exists(archiveFileName):
		return getTitles(wikiAddress)
	if archiveType == 'zip':
		zipArchive = zipfile.ZipFile(archiveFileName, 'r')
		zipArchive.extractall(fileNameRoot)
		zipArchive.close()
	else:
		mode = 'r'
		if archiveType == 'bz2':
			mode = 'r:bz2'
		tarArchive = tarfile.open(archiveFileName, mode)
		tarArchive.extractall(fileNameRoot)
		tarArchive.close()
	lastModifiedText = almoner.getFileText(os.path.join(fileNameRoot, 'last_modified.txt'))
	lastModifiedDatetime = datetime.datetime.strptime(lastModifiedText, globalDateTimeFormat)
	print('Last modified: %s' % lastModifiedDatetime)
	nowDatetime = datetime.datetime.today()
	nowMinusLast = nowDatetime - lastModifiedDatetime
	print('Now minus last: %s' % nowMinusLast)
	twentySixHours = 26 * 3600
	if getSeconds(nowMinusLast) > (24 * 5 + 22) * 3600:
		return getTitles(wikiAddress)
	recentPageAddress = wikiAddress + '/doku.php?do=recent&id=start&show_changes=pages&first[0]'
	lines = almoner.getTextLines(almoner.getInternetText(recentPageAddress))
	lineDatetime = None
	dateTitle = 'class="date">'
	linkTitle = 'class="wikilink1" title="'
	nameTitle = 'name="'
	start = 0
	titleSet = set([])
	while True:
		for lineIndex, line in enumerate(lines):
			if dateTitle in line:
				dateLine = lines[lineIndex + 1]
				dateString = dateLine[: dateLine.find('<')]
				if dateString.startswith('20'):
					dateString = dateString[2 :]
				lineDatetime = datetime.datetime.strptime(dateString, globalDateTimeFormat)
			if linkTitle in line:
				line = line[line.find(linkTitle) + len(linkTitle) :]
				title = line[: line.find('"')]
				if title != 'start':
					lastMinusLine = lastModifiedDatetime - lineDatetime
					if title in titleSet or getSeconds(lastMinusLine) > twentySixHours:
						titles = list(titleSet)
						titles.sort()
						return titles
					titleSet.add(title)
			if line.startswith('<input') and 'value="less recent' in line and nameTitle in line:
				line = line[line.find(nameTitle) + len(nameTitle) :]
				name = line[: line.find('"')]
				recentPageAddress = wikiAddress + '/doku.php?do=recent&id=start&show_changes=pages&' + name
		lines = almoner.getTextLines(almoner.getInternetText(recentPageAddress))
	return getTitles(wikiAddress)
예제 #7
0
파일: rater.py 프로젝트: jdbtracker/charity
def getRaters():
	raters = []
	lines = almoner.getTextLines(almoner.getFileText('rater.csv'))
	for line in lines[1 :]:
		words = line.split(',')
		if len(words) > 0:
			rater = words[0].strip()
			if rater != '':
				raters.append(rater)
	return raters
예제 #8
0
def getRecentNames(fileName, nowDatetime, previousDevtomeName, wikiAddress):
    'Get the recent user names.'
    lastModifiedText = almoner.getFileText(fileName)
    lastModifiedDatetime = nowDatetime - timedelta(30)
    if lastModifiedText != '':
        lines = almoner.getTextLines(lastModifiedText)
        if len(lines) > 0:
            words = lines[0].split(',')
            if len(words) > 1:
                lastModifiedDatetime = datetime.datetime.strptime(
                    words[1], globalDateTimeFormat)
    print('Last modified: %s' % lastModifiedDatetime)
    nowMinusLast = nowDatetime - lastModifiedDatetime
    paidNameSet = getPaidNameSet(previousDevtomeName)
    print('Now minus last: %s' % nowMinusLast)
    twentySixHours = 26 * 3600
    startChangesAddress = wikiAddress + '/doku.php?do=recent&id=start&show_changes=pages&'
    recentPageAddress = startChangesAddress + 'first[0]'
    lineDatetime = None
    dateTitle = 'class="date">'
    linkTitle = 'class="wikilink1" title="'
    nameTitle = 'name="'
    names = []
    while True:
        print('Parsing: %s' % recentPageAddress)
        lines = almoner.getTextLines(
            almoner.getInternetText(recentPageAddress))
        for lineIndex, line in enumerate(lines):
            if dateTitle in line:
                dateLine = lines[lineIndex + 1]
                dateString = dateLine[:dateLine.find('<')]
                if dateString.startswith('20'):
                    dateString = dateString[len('20'):]
                lineDatetime = datetime.datetime.strptime(
                    dateString, globalDateTimeFormat)
            if linkTitle in line:
                line = line[line.find(linkTitle) + len(linkTitle):]
                name = line[:line.find('"')]
                if name != 'start':
                    lastMinusLine = lastModifiedDatetime - lineDatetime
                    if getSeconds(lastMinusLine) > twentySixHours:
                        names.sort()
                        return names
                    if name.startswith('wiki:user:'******'wiki:user:'******'<input'
            ) and 'value="less recent' in line and nameTitle in line:
                line = line[line.find(nameTitle) + len(nameTitle):]
                name = line[:line.find('"')]
                recentPageAddress = startChangesAddress + name
        time.sleep(1)
    return None
예제 #9
0
def getPaidNameSet(previousDevtomeName):
    'Get the names of the paid writers.'
    lines = almoner.getTextLines(almoner.getFileText(previousDevtomeName))
    paidNameSet = set([])
    for line in lines[1:]:
        words = line.split(',')
        if len(words) > 0:
            firstWord = words[0].strip().lower()
            if firstWord != '':
                paidNameSet.add(firstWord)
    return paidNameSet
예제 #10
0
def getPaidNameSet(previousDevtomeName):
	'Get the names of the paid writers.'
	lines = almoner.getTextLines(almoner.getFileText(previousDevtomeName))
	paidNameSet = set([])
	for line in lines[1 :]:
		words = line.split(',')
		if len(words) > 0:
			firstWord = words[0].strip().lower()
			if firstWord != '':
				paidNameSet.add(firstWord)
	return paidNameSet
예제 #11
0
def getCountDictionary(round):
	'Get the weighted word count dictionary.'
	countDictionary = {}
	devtomeFileName = 'devtome_%s.csv' % round
	lines = almoner.getTextLines(almoner.getFileText(devtomeFileName))
	for line in lines[1 :]:
		words = line.split(',')
		if len(words) > 7:
			name = words[0].strip()
			if name != '':
				countDictionary[name] = int(words[7].strip())
	return countDictionary
예제 #12
0
파일: rater.py 프로젝트: jdbtracker/charity
def getWriters(round):
	writers = []
	lines = almoner.getTextLines(almoner.getFileText('devtome_%s.csv' % (round - 1)))
	for line in lines[1 :]:
		words = line.split(',')
		if len(words) > 1:
			name = words[0].strip()
			if name != '':
				writer = Writer(name)
				if len(writer.articles) > 0:
					writers.append(writer)
	return writers
예제 #13
0
def main():
    'Replace peers.'
    beginPeerString = '_beginpeers\n'
    endPeerString = '_endpeers\n'
    receiverIndex = 0
    receiverFileName = getReceiverFileName(receiverIndex)
    receiverText = almoner.getFileText(receiverFileName)
    peerLines = almoner.getTextLines(almoner.getFileText('peer.csv'))
    replacementString = beginPeerString + almoner.getTextByLines(
        peerLines) + endPeerString
    while receiverText != '':
        beginPeerIndex = receiverText.find(beginPeerString)
        endPeerEndIndex = receiverText.find(endPeerString) + len(endPeerString)
        betweenString = receiverText[beginPeerIndex:endPeerEndIndex]
        almoner.writeFileText('backup_receiver_%s.csv' % receiverIndex,
                              receiverText)
        replacedText = receiverText.replace(betweenString, replacementString)
        almoner.writeFileText(receiverFileName, replacedText)
        print('Replaced peers in file: ' + receiverFileName)
        receiverIndex += 1
        receiverFileName = getReceiverFileName(receiverIndex)
        receiverText = almoner.getFileText(receiverFileName, False)
예제 #14
0
def getPreviousRecipentSet(round, start):
    'Get the set of the previous recipient names.'
    previousRecipentSet = set([])
    for accountIndex in xrange(start, round):
        accountFileName = 'account_%s.csv' % accountIndex
        lines = almoner.getTextLines(almoner.getFileText(accountFileName))
        for line in lines[1:]:
            splitLine = line.split(',')
            if len(splitLine) > 1:
                name = splitLine[0].strip()
                if name != '':
                    previousRecipentSet.add(name.lower())
    return previousRecipentSet
예제 #15
0
def getRaterNames():
	'Get the rater names.'
	raterNames = []
	lines = almoner.getTextLines(almoner.getFileText('rater.csv'))
	for line in lines[1 :]:
		words = line.split(',')
		if len(words) > 0:
			raterName = words[0].strip().lower()
			if raterName != '':
				if raterName[0] == '*':
					raterName = raterName[1 :]
				raterNames.append(raterName)
	return raterNames
예제 #16
0
파일: newbie.py 프로젝트: moozilla/charity
def getPreviousRecipentSet(round, start):
	'Get the set of the previous recipient names.'
	previousRecipentSet = set([])
	for accountIndex in xrange(start, round):
		accountFileName = 'account_%s.csv' % accountIndex
		lines = almoner.getTextLines(almoner.getFileText(accountFileName))
		for line in lines[1 :]:
			splitLine = line.split(',')
			if len(splitLine) > 1:
				name = splitLine[0].strip()
				if name != '':
					previousRecipentSet.add(name)
	return previousRecipentSet
예제 #17
0
def getRatingDictionary(ratingFileName):
	'Get the rating median vote dictionary.'
	lines = almoner.getTextLines(almoner.getFileText(ratingFileName))
	if len(lines) < 2:
		return {}
	ratingDictionary = {}
	ratingMedianIndex = getRatingMedianIndex(lines[0])
	for line in lines[1 :]:
		words = line.split(',')
		if len(words) > ratingMedianIndex:
			name = words[0].strip().lower()
			if len(name) > 0:
				ratingDictionary[name] = float(words[ratingMedianIndex].strip().lower())
	return ratingDictionary
예제 #18
0
def writeOutput(arguments):
	'Write output.'
	if '-h' in arguments or '-help' in arguments:
		print(__doc__)
		return
	advertisingRevenue = int(almoner.getParameter(arguments, '0', 'revenue'))
	round = int(almoner.getParameter(arguments, '23', 'round'))
	advertisingFileName = almoner.getParameter(arguments, 'devtome', 'wiki')
	rootFileName = almoner.getParameter(arguments, 'devtome', 'wiki')
	currentFileName = almoner.getParameter(arguments, rootFileName + '_%s.csv' % round, 'current')
	previousFileName = almoner.getParameter(arguments, rootFileName + '_%s.csv' % (round - 1), 'previous')
	ratingFileName = almoner.getParameter(arguments, 'rating_%s.csv' % round, 'rating')
	viewFileName = almoner.getParameter(arguments, 'devtome_analytics_%s.csv' % round, 'view')
	categoryDictionary = {}
	nolines = almoner.getTextLines(almoner.getFileText(previousFileName))
	lines = [nolines[0]]
	titleLine = lines[0]
	titles = titleLine.split(',')
	backupFolder = rootFileName + '_articles'
	ratingDictionary = getRatingDictionary(ratingFileName)
	viewDictionary = getViewDictionary(viewFileName)
	authors = getAuthors(backupFolder, categoryDictionary, lines, ratingDictionary, titles, viewDictionary)
	totalTomecount = getTotalTomecount(advertisingRevenue, authors)
	tomecountText = getTomecountText(authors, totalTomecount)
	advertisingRevenueText = getAdvertisingRevenueText(authors)
	earningsText = getEarningsText(authors)
	activeWritersText = getActiveWritersText(authors, round)
	newArticlesText = getNewArticlesText(authors, round)
	warningsText = getWarningsText(authors)
	outputSummaryTo = almoner.getParameter(arguments, 'devtome_summary.txt', 'summary')
	almoner.writeFileText(currentFileName, tomecountText)
	outputActiveWritersTo = almoner.getParameter(arguments, 'devtome_active_writers.txt', 'writers')
	outputAdvertisingRevenueTo = almoner.getParameter(arguments, 'devtome_advertising_revenue.csv', 'advertising')
	outputEarningsTo = almoner.getParameter(arguments, 'devtome_earnings_%s.csv' % round, 'earnings')
	outputNewArticlesTo = almoner.getParameter(arguments, 'devtome_new_articles.txt', 'articles')
	outputWarningsTo = almoner.getParameter(arguments, 'devtome_warnings.txt', 'warnings')
	writeCategoryFiles(categoryDictionary, rootFileName)
	if advertisingRevenue > 0:
		if almoner.sendOutputTo(outputAdvertisingRevenueTo, advertisingRevenueText):
			print('The devtome advertising revenue file has been written to:\n%s\n' % outputAdvertisingRevenueTo)
	if almoner.sendOutputTo(outputEarningsTo, earningsText):
		print('The devtome earnings file has been written to:\n%s\n' % outputEarningsTo)
	if almoner.sendOutputTo(outputNewArticlesTo, newArticlesText):
		print('The devtome new articles file has been written to:\n%s\n' % outputNewArticlesTo)
	if almoner.sendOutputTo(outputActiveWritersTo, activeWritersText):
		print('The devtome active writers file has been written to:\n%s\n' % outputActiveWritersTo)
	if almoner.sendOutputTo(outputSummaryTo, getSummaryText(earningsText, round, totalTomecount)):
		print('The summary file has been written to:\n%s\n' % outputSummaryTo)
	if almoner.sendOutputTo(outputWarningsTo, warningsText):
		print('The devtome warnings file has been written to:\n%s\n' % outputWarningsTo)
예제 #19
0
def getRecentNames(fileName, nowDatetime, previousDevtomeName, wikiAddress):
	'Get the recent user names.'
	lastModifiedText = almoner.getFileText(fileName)
	lastModifiedDatetime = nowDatetime - timedelta(30)
	if lastModifiedText != '':
		lines = almoner.getTextLines(lastModifiedText)
		if len(lines) > 0:
			words = lines[0].split(',')
			if len(words) > 1:
				lastModifiedDatetime = datetime.datetime.strptime(words[1], globalDateTimeFormat)
	print('Last modified: %s' % lastModifiedDatetime)
	nowMinusLast = nowDatetime - lastModifiedDatetime
	paidNameSet = getPaidNameSet(previousDevtomeName)
	print('Now minus last: %s' % nowMinusLast)
	twentySixHours = 26 * 3600
	startChangesAddress = wikiAddress + '/doku.php?do=recent&id=start&show_changes=pages&'
	recentPageAddress = startChangesAddress + 'first[0]'
	lineDatetime = None
	dateTitle = 'class="date">'
	linkTitle = 'class="wikilink1" title="'
	nameTitle = 'name="'
	names = []
	while True:
		print('Parsing: %s' % recentPageAddress)
		lines = almoner.getTextLines(almoner.getInternetText(recentPageAddress))
		for lineIndex, line in enumerate(lines):
			if dateTitle in line:
				dateLine = lines[lineIndex + 1]
				dateString = dateLine[: dateLine.find('<')]
				if dateString.startswith('20'):
					dateString = dateString[len('20') :]
				lineDatetime = datetime.datetime.strptime(dateString, globalDateTimeFormat)
			if linkTitle in line:
				line = line[line.find(linkTitle) + len(linkTitle) :]
				name = line[: line.find('"')]
				if name != 'start':
					lastMinusLine = lastModifiedDatetime - lineDatetime
					if getSeconds(lastMinusLine) > twentySixHours:
						names.sort()
						return names
					if name.startswith('wiki:user:'******'wiki:user:'******'<input') and 'value="less recent' in line and nameTitle in line:
				line = line[line.find(nameTitle) + len(nameTitle) :]
				name = line[: line.find('"')]
				recentPageAddress = startChangesAddress + name
		time.sleep(1)
	return None
예제 #20
0
def getRatingDictionary(ratingFileName):
	'Get the rating median vote dictionary.'
	lines = almoner.getTextLines(almoner.getFileText(ratingFileName))
	if len(lines) < 2:
		return {}
	ratingDictionary = {}
	ratingMedianIndex = getRatingMedianIndex(lines[0])
	for line in lines[1 :]:
		words = line.split(',')
		if len(words) > ratingMedianIndex:
			name = words[0].strip().lower()
			if len(name) > 0:
				ratingDictionary[name] = float(words[ratingMedianIndex].strip().lower())
	return ratingDictionary
예제 #21
0
def writeOutput(arguments):
	'Write output.'
	if '-h' in arguments or '-help' in arguments:
		print(__doc__)
		return
	advertisingRevenue = int(almoner.getParameter(arguments, '0', 'revenue'))
	round = int(almoner.getParameter(arguments, '23', 'round'))
	advertisingFileName = almoner.getParameter(arguments, 'devtome', 'wiki')
	rootFileName = almoner.getParameter(arguments, 'devtome', 'wiki')
	currentFileName = almoner.getParameter(arguments, rootFileName + '_%s.csv' % round, 'current')
	previousFileName = almoner.getParameter(arguments, rootFileName + '_%s.csv' % (round - 1), 'previous')
	ratingFileName = almoner.getParameter(arguments, 'rating_%s.csv' % round, 'rating')
	viewFileName = almoner.getParameter(arguments, 'devtome_analytics_%s.csv' % round, 'view')
	categoryDictionary = {}
	lines = almoner.getTextLines(almoner.getFileText(previousFileName))
	titleLine = lines[0]
	titles = titleLine.split(',')
	backupFolder = rootFileName + '_articles'
	ratingDictionary = getRatingDictionary(ratingFileName)
	viewDictionary = getViewDictionary(viewFileName)
	authors = getAuthors(backupFolder, categoryDictionary, lines, ratingDictionary, titles, viewDictionary)
	totalTomecount = getTotalTomecount(advertisingRevenue, authors)
	tomecountText = getTomecountText(authors, totalTomecount)
	advertisingRevenueText = getAdvertisingRevenueText(authors)
	earningsText = getEarningsText(authors)
	activeWritersText = getActiveWritersText(authors, round)
	newArticlesText = getNewArticlesText(authors, round)
	warningsText = getWarningsText(authors)
	outputSummaryTo = almoner.getParameter(arguments, 'devtome_summary.txt', 'summary')
	almoner.writeFileText(currentFileName, tomecountText)
	outputActiveWritersTo = almoner.getParameter(arguments, 'devtome_active_writers.txt', 'writers')
	outputAdvertisingRevenueTo = almoner.getParameter(arguments, 'devtome_advertising_revenue.csv', 'advertising')
	outputEarningsTo = almoner.getParameter(arguments, 'devtome_earnings_%s.csv' % round, 'earnings')
	outputNewArticlesTo = almoner.getParameter(arguments, 'devtome_new_articles.txt', 'articles')
	outputWarningsTo = almoner.getParameter(arguments, 'devtome_warnings.txt', 'warnings')
	writeCategoryFiles(categoryDictionary, rootFileName)
	if advertisingRevenue > 0:
		if almoner.sendOutputTo(outputAdvertisingRevenueTo, advertisingRevenueText):
			print('The devtome advertising revenue file has been written to:\n%s\n' % outputAdvertisingRevenueTo)
	if almoner.sendOutputTo(outputEarningsTo, earningsText):
		print('The devtome earnings file has been written to:\n%s\n' % outputEarningsTo)
	if almoner.sendOutputTo(outputNewArticlesTo, newArticlesText):
		print('The devtome new articles file has been written to:\n%s\n' % outputNewArticlesTo)
	if almoner.sendOutputTo(outputActiveWritersTo, activeWritersText):
		print('The devtome active writers file has been written to:\n%s\n' % outputActiveWritersTo)
	if almoner.sendOutputTo(outputSummaryTo, getSummaryText(earningsText, round, totalTomecount)):
		print('The summary file has been written to:\n%s\n' % outputSummaryTo)
	if almoner.sendOutputTo(outputWarningsTo, warningsText):
		print('The devtome warnings file has been written to:\n%s\n' % outputWarningsTo)
예제 #22
0
def writeOutput(arguments):
	'Write output.'
	if '-h' in arguments or '-help' in arguments:
		print(__doc__)
		return
	round = int(almoner.getParameter(arguments, '23', 'round'))
	publishersFileName = almoner.getParameter(arguments, 'devtome_%s.csv' % round, 'publishers')
	lines = almoner.getTextLines(almoner.getFileText(publishersFileName))
	outputEarningsTo = almoner.getParameter(arguments, 'marketing_earnings_%s.csv' % round, 'earnings')
	outputSummaryTo = almoner.getParameter(arguments, 'marketing_summary.txt', 'summary')
	publishers = getPublishers(lines, round)
	earningsText = getEarningsText(publishers)
	if almoner.sendOutputTo(outputEarningsTo, earningsText):
		print('The marketing earnings bounty file has been written to:\n%s\n' % outputEarningsTo)
	if almoner.sendOutputTo(outputSummaryTo, getSummaryText(earningsText, publishers, round)):
		print('The summary file has been written to:\n%s\n' % outputSummaryTo)
예제 #23
0
def writeOutput(arguments):
	'Write output.'
	if '-h' in arguments or '-help' in arguments:
		print(__doc__)
		return
	round = int(almoner.getParameter(arguments, '23', 'round'))
	publishersFileName = almoner.getParameter(arguments, 'devtome_%s.csv' % round, 'publishers')
	lines = almoner.getTextLines(almoner.getFileText(publishersFileName))
	outputEarningsTo = almoner.getParameter(arguments, 'marketing_earnings_%s.csv' % round, 'earnings')
	outputSummaryTo = almoner.getParameter(arguments, 'marketing_summary.txt', 'summary')
	workerNameSet = set(account.getRecipientDictionary(round).keys())
	publishers = getPublishers(lines, workerNameSet)
	earningsText = getEarningsText(publishers)
	if almoner.sendOutputTo(outputEarningsTo, earningsText):
		print('The marketing earnings bounty file has been written to:\n%s\n' % outputEarningsTo)
	if almoner.sendOutputTo(outputSummaryTo, getSummaryText(earningsText, publishers, round)):
		print('The summary file has been written to:\n%s\n' % outputSummaryTo)
예제 #24
0
def getWriterNames(writerFileName):
	'Get the writer names.'
	writerNames = []
	lines = almoner.getTextLines(almoner.getFileText(writerFileName))
	if lines[0].startswith('Create:'):
		isWriterName = False
		for line in lines[1 :]:
			if isWriterName:
				writerNames.append(line.strip().lower())
			if line.startswith('Writer names:'):
				isWriterName = True
		return writerNames
	for line in lines[1 :]:
		words = line.split(',')
		if len(words) > 0:
			name = words[0].strip().lower()
			if name != '':
				writerNames.append(name)
	return writerNames
예제 #25
0
def getWeightedWordCounts(lastRound, start):
	'Get the weighted word counts.'
	weightedWordCounts = []
	for round in xrange(start, lastRound):
		devtomeFileName = 'devtome_%s.csv' % round
		if not os.path.exists(devtomeFileName):
			return weightedWordCounts
		devtomeText = almoner.getFileText(devtomeFileName)
		if devtomeText == '':
			return weightedWordCounts
		weightedWordCountIndex = -1
		for line in almoner.getTextLines(devtomeText):
			words = line.strip().split(',')
			if len(words) > 1:
				if weightedWordCountIndex != -1:
					weightedWordCounts.append(int(words[weightedWordCountIndex]))
					weightedWordCountIndex = -1
				if words[0].strip() == '' and words[1].strip() == 'Totals':
					weightedWordCountIndex = words.index('Weighted Word Count')
	return weightedWordCounts
예제 #26
0
def getWeightedWordCounts(lastRound, start):
    'Get the weighted word counts.'
    weightedWordCounts = []
    for round in xrange(start, lastRound):
        devtomeFileName = 'devtome_%s.csv' % round
        if not os.path.exists(devtomeFileName):
            return weightedWordCounts
        devtomeText = almoner.getFileText(devtomeFileName)
        if devtomeText == '':
            return weightedWordCounts
        weightedWordCountIndex = -1
        for line in almoner.getTextLines(devtomeText):
            words = line.strip().split(',')
            if len(words) > 1:
                if weightedWordCountIndex != -1:
                    weightedWordCounts.append(
                        int(words[weightedWordCountIndex]))
                    weightedWordCountIndex = -1
                if words[0].strip() == '' and words[1].strip() == 'Totals':
                    weightedWordCountIndex = words.index('Weighted Word Count')
    return weightedWordCounts
예제 #27
0
def getArticles():
    "Get the articles."
    articles = []
    authorDictionary = {}
    fileNameRoot = "devtome_articles"
    archiveFileName = fileNameRoot + ".zip"
    zipArchive = zipfile.ZipFile(archiveFileName, "r")
    zipArchive.extractall(fileNameRoot)
    zipArchive.close()
    names = os.listdir(fileNameRoot)
    for name in names:
        filePath = os.path.join(fileNameRoot, name)
        text = almoner.getFileText(filePath)
        if name.startswith("wiki:user:"******"wiki:user:") :], text)
        else:
            longWords = getLongWords(text)
            if len(longWords) > 40:
                articles.append(Article(longWords, name))
    for article in articles:
        if article.name in authorDictionary:
            article.author = authorDictionary[article.name]
    shutil.rmtree(fileNameRoot)
    return articles
예제 #28
0
def getPreviousLines(round):
	'Get the lines from the rating text of the previous round.'
	return almoner.getTextLines(almoner.getFileText('rating_%s.csv' % (round - 1)))
예제 #29
0
def getRecentTitles(archiveType, fileNameRoot, wikiAddress):
    'Get all titles of the dokuwiki.'
    archiveFileName = fileNameRoot + '.' + archiveType
    if not os.path.exists(archiveFileName):
        return getTitles(wikiAddress)
    if archiveType == 'zip':
        zipArchive = zipfile.ZipFile(archiveFileName, 'r')
        zipArchive.extractall(fileNameRoot)
        zipArchive.close()
    else:
        mode = 'r'
        if archiveType == 'bz2':
            mode = 'r:bz2'
        tarArchive = tarfile.open(archiveFileName, mode)
        tarArchive.extractall(fileNameRoot)
        tarArchive.close()
    lastModifiedText = almoner.getFileText(
        os.path.join(fileNameRoot, 'last_modified.txt'))
    lastModifiedDatetime = datetime.datetime.strptime(lastModifiedText,
                                                      globalDateTimeFormat)
    print('Last modified: %s' % lastModifiedDatetime)
    nowDatetime = datetime.datetime.today()
    nowMinusLast = nowDatetime - lastModifiedDatetime
    print('Now minus last: %s' % nowMinusLast)
    twentySixHours = 26 * 3600
    if getSeconds(nowMinusLast) > (24 * 5 + 22) * 3600:
        return getTitles(wikiAddress)
    recentPageAddress = wikiAddress + '/doku.php?do=recent&id=start&show_changes=pages&first[0]'
    lines = almoner.getTextLines(almoner.getInternetText(recentPageAddress))
    lineDatetime = None
    dateTitle = 'class="date">'
    linkTitle = 'class="wikilink1" title="'
    nameTitle = 'name="'
    start = 0
    titleSet = set([])
    while True:
        for lineIndex, line in enumerate(lines):
            if dateTitle in line:
                dateLine = lines[lineIndex + 1]
                dateString = dateLine[:dateLine.find('<')]
                if dateString.startswith('20'):
                    dateString = dateString[2:]
                lineDatetime = datetime.datetime.strptime(
                    dateString, globalDateTimeFormat)
            if linkTitle in line:
                line = line[line.find(linkTitle) + len(linkTitle):]
                title = line[:line.find('"')]
                if title != 'start':
                    lastMinusLine = lastModifiedDatetime - lineDatetime
                    if title in titleSet or getSeconds(
                            lastMinusLine) > twentySixHours:
                        titles = list(titleSet)
                        titles.sort()
                        return titles
                    titleSet.add(title)
            if line.startswith(
                    '<input'
            ) and 'value="less recent' in line and nameTitle in line:
                line = line[line.find(nameTitle) + len(nameTitle):]
                name = line[:line.find('"')]
                recentPageAddress = wikiAddress + '/doku.php?do=recent&id=start&show_changes=pages&' + name
        lines = almoner.getTextLines(
            almoner.getInternetText(recentPageAddress))
    return getTitles(wikiAddress)