Exemple #1
0
def moderatesignups():
    global commentHashesAndComments
    commentHashesAndComments = {}
    stringio = StringIO()
    stringio.write('<html>\n<head>\n</head>\n\n')

    # redditSession = loginAndReturnRedditSession()
    redditSession = loginOAuthAndReturnRedditSession()
    submissions = getSubmissionsForRedditSession(redditSession)
    flat_comments = getCommentsForSubmissions(submissions)
    retiredHashes = retiredCommentHashes()
    i = 1
    stringio.write('<iframe name="invisibleiframe" style="display:none;"></iframe>\n')
    stringio.write("<h3>")
    stringio.write(os.getcwd())
    stringio.write("<br>\n")
    for submission in submissions:
        stringio.write(submission.title)
        stringio.write("<br>\n")
    stringio.write("</h3>\n\n")
    stringio.write('<form action="copydisplayduringsignuptoclipboard.html" method="post" target="invisibleiframe">')
    stringio.write('<input type="submit" value="Copy display-during-signup.py stdout to clipboard">')
    stringio.write('</form>')
    for comment in flat_comments:
        # print comment.is_root
        # print comment.score
        i += 1
        commentHash = sha1()
        commentHash.update(comment.permalink)
        commentHash.update(comment.body.encode('utf-8'))
        commentHash = commentHash.hexdigest()
        if commentHash not in retiredHashes:
            commentHashesAndComments[commentHash] = comment
            authorName = str(comment.author)  # can be None if author was deleted.  So check for that and skip if it's None.
            stringio.write("<hr>\n")
            stringio.write('<font color="blue"><b>')
            stringio.write(authorName)  # can be None if author was deleted.  So check for that and skip if it's None.
            stringio.write('</b></font><br>')
            if ParticipantCollection().hasParticipantNamed(authorName):
                stringio.write(' <small><font color="green">(member)</font></small>')
                # if ParticipantCollection().participantNamed(authorName).isStillIn:
                #    stringio.write(' <small><font color="green">(in)</font></small>')
                # else:
                #    stringio.write(' <small><font color="red">(out)</font></small>')
            else:
                stringio.write(' <small><font color="red">(not a member)</font></small>')
            stringio.write('<form action="takeaction.html" method="post" target="invisibleiframe">')
            stringio.write('<input type="submit" name="actiontotake" value="Signup" style="color:white;background-color:green">')
            # stringio.write('<input type="submit" name="actiontotake" value="Signup and checkin">')
            # stringio.write('<input type="submit" name="actiontotake" value="Relapse">')
            # stringio.write('<input type="submit" name="actiontotake" value="Reinstate">')
            stringio.write('<input type="submit" name="actiontotake" value="Skip comment">')
            stringio.write('<input type="submit" name="actiontotake" value="Skip comment and don\'t upvote">')
            stringio.write('<input type="hidden" name="username" value="' + b64encode(authorName) + '">')
            stringio.write('<input type="hidden" name="commenthash" value="' + commentHash + '">')
            stringio.write('<input type="hidden" name="commentpermalink" value="' + comment.permalink + '">')
            stringio.write('</form>')

            stringio.write(bleach.clean(markdown.markdown(comment.body.encode('utf-8')), tags=['p']))
            stringio.write("\n<br><br>\n\n")

    stringio.write('</html>')
    pageString = stringio.getvalue()
    stringio.close()
    return Response(pageString, mimetype='text/html')
    '../stayclean-2019-november/participants.txt',
    '../stayclean-2019-december/participants.txt',
    '../stayclean-2020-january/participants.txt',
    '../stayclean-2020-february/participants.txt',
    '../stayclean-2020-march/participants.txt',
    '../stayclean-2020-april/participants.txt',
    '../stayclean-2020-may/participants.txt',
    '../stayclean-2020-june/participants.txt',
    '../stayclean-2020-july/participants.txt',
    '../stayclean-2020-august/participants.txt',
    '../stayclean-2020-september/participants.txt', './participants.txt'
]

sortedRelapseDates = []
for participantFileName in participantFileNames:
    participants = ParticipantCollection(fileNameString=participantFileName)
    sortedRelapseDates = sortedRelapseDates + participants.allRelapseDates()
sortedRelapseDates.sort()
earliestReportDate = sortedRelapseDates[0]
latestReportDate = sortedRelapseDates[-1]
reportDates = []
numberOfRelapsesPerDate = []
reportDatesAndNumberOfRelapses = {}
dayOfWeekIndexesAndNumberOfInstances = {
    0: 0,
    1: 0,
    2: 0,
    3: 0,
    4: 0,
    5: 0,
    6: 0
Exemple #3
0
    31: 'thirty-first'
}[currentDayOfMonthIndex]
currentDayOfWeekName = {
    0: 'Monday',
    1: 'Tuesday',
    2: 'Wednesday',
    3: 'Thursday',
    4: 'Friday',
    5: 'Saturday',
    6: 'Sunday'
}[datetime.date.today().weekday()]

# TODO: testing
# currentDayOfMonthIndex = 28

participants = ParticipantCollection()
initialNumber = participants.size()


def templateForParticipants():
    answer = ""
    answer += "Here are the **INITIAL_NUMBER participants** who have already signed up:\n\n"
    for participant in participants.participants:
        answer += "/u/" + participant.name
        answer += "\n\n"
    return answer


def templateForTooEarly():
    answer = ""
    answer += "(Too early.  Come back on CURRENT_MONTH_NAME " + str(
def moderatechallenge():
    global commentHashesAndComments
    global submission
    currentDayOfMonthIndex = datetime.date.today().day
    currentMonthIndex = datetime.date.today().month
    lateCheckinGracePeriodIsInEffect = currentDayOfMonthIndex <= 14 and currentMonthIndex == 1
    commentHashesAndComments = {}
    stringio = StringIO()
    stringio.write('<html>\n<head>\n</head>\n\n')

    # redditSession = loginAndReturnRedditSession()
    redditSession = loginOAuthAndReturnRedditSession()
    submission = getSubmissionForRedditSession(redditSession)
    flat_comments = getCommentsForSubmission(submission)
    retiredHashes = retiredCommentHashes()
    i = 1
    stringio.write(
        '<iframe name="invisibleiframe" style="display:none;"></iframe>\n')
    stringio.write("<h3>")
    stringio.write(os.getcwd())
    stringio.write("<br>\n")
    stringio.write(submission.title)
    stringio.write("</h3>\n\n")
    stringio.write(
        '<form action="copydisplaytoclipboard.html" method="post" target="invisibleiframe">'
    )
    stringio.write(
        '<input type="submit" name="actiontotake" value="Copy display.py stdout to clipboard">'
    )
    stringio.write(
        '<input type="submit" name="actiontotake" value="Automatically post display.py stdout">'
    )
    stringio.write('</form>')
    for comment in flat_comments:
        # print comment.is_root
        # print comment.score
        i += 1
        commentHash = sha1()
        commentHash.update(comment.fullname)
        commentHash.update(comment.body.encode('utf-8'))
        commentHash = commentHash.hexdigest()
        if commentHash not in retiredHashes:
            commentHashesAndComments[commentHash] = comment
            authorName = str(
                comment.author
            )  # can be None if author was deleted.  So check for that and skip if it's None.
            participant = ParticipantCollection().participantNamed(authorName)
            stringio.write("<hr>\n")
            stringio.write('<font color="blue"><b>')
            stringio.write(authorName)
            stringio.write('</b></font><br>')
            if ParticipantCollection().hasParticipantNamed(authorName):
                stringio.write(
                    ' <small><font color="green">(member)</font></small>')
                if participant.isStillIn:
                    stringio.write(
                        ' <small><font color="green">(still in)</font></small>'
                    )
                else:
                    stringio.write(
                        ' <small><font color="red">(out)</font></small>')
                if participant.hasCheckedIn:
                    stringio.write(
                        ' <small><font color="green">(checked in)</font></small>'
                    )
                else:
                    stringio.write(
                        ' <small><font color="orange">(not checked in)</font></small>'
                    )
                if participant.hasRelapsed:
                    stringio.write(
                        ' <small><font color="red">(relapsed)</font></small>')
                else:
                    stringio.write(
                        ' <small><font color="green">(not relapsed)</font></small>'
                    )
            else:
                stringio.write(
                    ' <small><font color="red">(not a member)</font></small>')
            stringio.write(
                '<form action="takeaction.html" method="post" target="invisibleiframe">'
            )

            # stringio.write('<input type="submit" name="actiontotake" value="Checkin" style="color:white;background-color:green">')
            # stringio.write('<input type="submit" name="actiontotake" value="Signup and checkin">')

            if lateCheckinGracePeriodIsInEffect:
                stringio.write(
                    '<input type="submit" name="actiontotake" value="Checkin">'
                )
                stringio.write(
                    '<input type="submit" name="actiontotake" value="Signup and checkin" style="color:white;background-color:green">'
                )
            else:
                stringio.write(
                    '<input type="submit" name="actiontotake" value="Checkin" style="color:white;background-color:green">'
                )
                stringio.write(
                    '<input type="submit" name="actiontotake" value="Signup and checkin">'
                )

            stringio.write(
                '<input type="submit" name="actiontotake" value="Relapse" style="color:white;background-color:red">'
            )
            stringio.write(
                '<input type="submit" name="actiontotake" value="Reinstate with automatic comment">'
            )
            stringio.write(
                '<input type="submit" name="actiontotake" value="Reply with sorry-too-late comment">'
            )
            stringio.write(
                '<input type="submit" name="actiontotake" value="Skip comment">'
            )
            stringio.write(
                '<input type="submit" name="actiontotake" value="Skip comment and don\'t upvote">'
            )
            stringio.write('<input type="hidden" name="username" value="' +
                           b64encode(authorName) + '">')
            stringio.write('<input type="hidden" name="commenthash" value="' +
                           commentHash + '">')
            # stringio.write('<input type="hidden" name="commentpermalink" value="' + comment.permalink + '">')
            stringio.write('</form>')
            stringio.write(
                bleach.clean(markdown.markdown(comment.body.encode('utf-8')),
                             tags=['p']))
            stringio.write("\n<br><br>\n\n")
    stringio.write('</html>')
    pageString = stringio.getvalue()
    stringio.close()
    return Response(pageString, mimetype='text/html')