コード例 #1
0
# This script gets run on the first day of the following month, and that month's URL is
# what goes here.  E.g. If this directory is the directory for February, this script gets
# run on March 1, and this URL is the URL for the March challenge page.
nextMonthURL = "https://www.reddit.com/r/pornfree/comments/55csdt/stay_clean_october_this_thread_updated_daily/"

# If this directory is the directory for November, this script gets run on December 1,
# and currentMonthIndex gets the index of November, i.e. 11.
currentMonthIndex = datetime.date.today().month - 1
if currentMonthIndex == 0:
    currentMonthIndex = 12

currentMonthName = {1: 'January', 2: 'February', 3: 'March', 4: 'April', 5: 'May', 6: 'June', 7: 'July', 8: 'August', 9: 'September', 10: 'October', 11: 'November', 12: 'December'}[currentMonthIndex]
nextMonthIndex = currentMonthIndex % 12 + 1
nextMonthName = {1: 'January', 2: 'February', 3: 'March', 4: 'April', 5: 'May', 6: 'June', 7: 'July', 8: 'August', 9: 'September', 10: 'October', 11: 'November', 12: 'December'}[nextMonthIndex]

participants = ParticipantCollection()
numberStillIn = participants.sizeOfParticipantsWhoAreStillIn()
initialNumber = participants.size()
percentStillIn = int(round(100 * numberStillIn / initialNumber, 0))


def templateForParticipants():
    answer = ""
    for participant in participants.participantsWhoAreStillInAndHaveCheckedIn():
        answer += "/u/" + participant.name
        answer += "\n\n"
    return answer


def templateToUse():
    answer = ""
コード例 #2
0
    '../stayclean-2015-march/participants.txt',
    '../stayclean-2015-april/participants.txt',
    '../stayclean-2015-may/participants.txt',
    '../stayclean-2015-june/participants.txt',
    '../stayclean-2015-july/participants.txt',
    '../stayclean-2015-august/participants.txt',
    '../stayclean-2015-september/participants.txt',
    '../stayclean-2015-october/participants.txt',
    '../stayclean-2015-november/participants.txt',
    '../stayclean-2015-december/participants.txt',
    '../stayclean-2016-january/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
コード例 #3
0
#!/usr/bin/python3
import sys
from participantCollection import ParticipantCollection


if __name__ == "__main__":
    names = sys.argv[1::]
    participants = ParticipantCollection()
    for name in names:
        if participants.hasParticipantNamed(name):
            print(f"{name} has already signed up.  Skipping.")
        else:
            participants.addNewParticipantNamed(name)
            print(f"just added {name}")
    participants.save()

コード例 #4
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.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.
            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')
コード例 #5
0
def moderatechallenge():
    currentDayOfMonthIndex = datetime.date.today().day
    lateCheckinGracePeriodIsInEffect = currentDayOfMonthIndex <= 3
    global commentHashesAndComments
    global submission
    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>')
    stringio.write(
        '<form action="updategooglechart.html" method="post" target="invisibleiframe">'
    )
    stringio.write('<input type="submit" value="update-google-chart.py">')
    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">'
            )
            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')
コード例 #6
0
#!/usr/bin/python
from participantCollection import ParticipantCollection


participants = ParticipantCollection()
for participant in participants.participantsWhoAreStillIn():
    if not participant.hasCheckedIn:
        print "disqualifying " + participant.name
        participant.isStillIn = False
participants.save()

コード例 #7
0
#!/usr/bin/env python3
# TODO: issues with new oauth2 stuff.  Keep using older version of Python for now.
# #!/usr/bin/env python
from participantCollection import ParticipantCollection


participants = ParticipantCollection()
for participant in participants.participantsWhoAreStillIn():
    participant.hasCheckedIn = False
participants.save()

コード例 #8
0
                        '../stayclean-2015-april/participants.txt',
                        '../stayclean-2015-may/participants.txt',
                        '../stayclean-2015-june/participants.txt',
                        '../stayclean-2015-july/participants.txt',
                        '../stayclean-2015-august/participants.txt',
                        '../stayclean-2015-september/participants.txt',
                        '../stayclean-2015-october/participants.txt',
                        '../stayclean-2015-november/participants.txt',
                        '../stayclean-2015-december/participants.txt',
                        '../stayclean-2016-january/participants.txt',
                        '../stayclean-2016-february/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}

reportDate = earliestReportDate
while reportDate <= latestReportDate:
    reportDatesAndNumberOfRelapses[reportDate] = 0
    # dayOfWeekIndexesAndNumberOfInstances[reportDate.weekday()] = dayOfWeekIndexesAndNumberOfInstances[reportDate.weekday()] + 1
    dayOfWeekIndexesAndNumberOfInstances[reportDate.weekday()] += 1
    reportDate += datetime.timedelta(days=1)
コード例 #9
0
currentMonthURL = "https://www.reddit.com/r/pornfree/comments/4m14e4/stay_clean_june_this_thread_updated_daily_check/"

currentMonthIndex = datetime.date.today().month
currentMonthPenultimateDayIndex = currentMonthTotalDays - 1
currentMonthName = {1: 'January', 2: 'February', 3: 'March', 4: 'April', 5: 'May', 6: 'June', 7: 'July', 8: 'August', 9: 'September', 10: 'October', 11: 'November', 12: 'December'}[currentMonthIndex]
nextMonthIndex = currentMonthIndex % 12 + 1
nextMonthName = {1: 'January', 2: 'February', 3: 'March', 4: 'April', 5: 'May', 6: 'June', 7: 'July', 8: 'August', 9: 'September', 10: 'October', 11: 'November', 12: 'December'}[nextMonthIndex]
uppercaseMonth = string.upper(nextMonthName)
currentDayOfMonthIndex = datetime.date.today().day
currentDayOfMonthName = {1: 'first', 2: 'second', 3: 'third', 4: 'fourth', 5: 'fifth', 6: 'sixth', 7: 'seventh', 8: 'eighth', 9: 'ninth', 10: 'tenth', 11: 'eleventh', 12: 'twelfth', 13: 'thirteenth', 14: 'fourteenth', 15: 'fifteenth', 16: 'sixteenth', 17: 'seventeenth', 18: 'eighteenth', 19: 'nineteenth', 20: 'twentieth', 21: 'twenty-first', 22: 'twenty-second', 23: 'twenty-third', 24: 'twenty-fourth', 25: 'twenty-fifth', 26: 'twenty-sixth', 27: 'twenty-seventh', 28: 'twenty-eighth', 29: 'twenty-ninth', 30: 'thirtieth', 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(currentMonthTotalDays - 6) + ")\n"
コード例 #10
0
ファイル: checkin.py プロジェクト: foobarbazblarg/stayclean
#!/usr/bin/python
import sys
from participantCollection import ParticipantCollection


names = sys.argv[1::]

participants = ParticipantCollection()
for name in names:
    if participants.hasParticipantNamed(name):
        participants.participantNamed(name).hasCheckedIn = True
        print "just checked in " + name
    else:
        print "*** WARNING: " + name + " is not present in participants.txt"
participants.save()

コード例 #11
0
ファイル: reinstate.py プロジェクト: foobarbazblarg/stayclean
#!/usr/bin/python
# TODO: issues with new oauth2 stuff.  Keep using older version of Python for now.
# #!/usr/bin/env python
import sys
from participantCollection import ParticipantCollection

names = sys.argv[1::]

participants = ParticipantCollection()
for name in names:
    if participants.hasParticipantNamed(name):
        participants.participantNamed(name).isStillIn = True
        print "just reinstated " + name
    else:
        print "*** WARNING: " + name + " is not present in participants.txt"
participants.save()
コード例 #12
0
#!/usr/bin/python
# TODO: issues with new oauth2 stuff.  Keep using older version of Python for now.
# #!/usr/bin/env python
from participantCollection import ParticipantCollection
import pyperclip

participants = ParticipantCollection()


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


outputString = stringToPrint()
print("=============================================================")
print(outputString)
print("=============================================================")
pyperclip.copy(outputString)
コード例 #13
0
ファイル: signup.py プロジェクト: foobarbazblarg/stayclean
#!/usr/bin/python
import sys
from participantCollection import ParticipantCollection


names = sys.argv[1::]

participants = ParticipantCollection()
for name in names:
    if participants.hasParticipantNamed(name):
        print name + " has already signed up.  Skipping."
    else:
        participants.addNewParticipantNamed(name)
        print "just added " + name
participants.save()

コード例 #14
0
ファイル: reinstate.py プロジェクト: foobarbazblarg/stayclean
#!/usr/bin/python
import sys
from participantCollection import ParticipantCollection


names = sys.argv[1::]

participants = ParticipantCollection()
for name in names:
    if participants.hasParticipantNamed(name):
        participants.participantNamed(name).isStillIn = True
        print "just reinstated " + name
    else:
        print "*** WARNING: " + name + " is not present in participants.txt"
participants.save()

コード例 #15
0
ファイル: display.py プロジェクト: foobarbazblarg/stayclean
# Edit Me!
# currentMonthTotalDays = 31

currentMonthIndex = datetime.date.today().month
currentMonthPenultimateDayIndex = editme.currentMonthTotalDays - 1
currentMonthName = {1: 'January', 2: 'February', 3: 'March', 4: 'April', 5: 'May', 6: 'June', 7: 'July', 8: 'August', 9: 'September', 10: 'October', 11: 'November', 12: 'December'}[currentMonthIndex]
nextMonthIndex = currentMonthIndex % 12 + 1
nextMonthName = {1: 'January', 2: 'February', 3: 'March', 4: 'April', 5: 'May', 6: 'June', 7: 'July', 8: 'August', 9: 'September', 10: 'October', 11: 'November', 12: 'December'}[nextMonthIndex]
currentDayOfMonthIndex = datetime.date.today().day
# TODO: testing...
# currentDayOfMonthIndex = 31
currentDayOfMonthName = {1: 'first', 2: 'second', 3: 'third', 4: 'fourth', 5: 'fifth', 6: 'sixth', 7: 'seventh', 8: 'eighth', 9: 'ninth', 10: 'tenth', 11: 'eleventh', 12: 'twelfth', 13: 'thirteenth', 14: 'fourteenth', 15: 'fifteenth', 16: 'sixteenth', 17: 'seventeenth', 18: 'eighteenth', 19: 'nineteenth', 20: 'twentieth', 21: 'twenty-first', 22: 'twenty-second', 23: 'twenty-third', 24: 'twenty-fourth', 25: 'twenty-fifth', 26: 'twenty-sixth', 27: 'twenty-seventh', 28: 'twenty-eighth', 29: 'twenty-ninth', 30: 'thirtieth', 31: 'thirty-first'}[currentDayOfMonthIndex]
currentDayOfWeekName = {0: 'Monday', 1: 'Tuesday', 2: 'Wednesday', 3: 'Thursday', 4: 'Friday', 5: 'Saturday', 6: 'Sunday'}[datetime.date.today().weekday()]


participants = ParticipantCollection()
numberStillIn = participants.sizeOfParticipantsWhoAreStillIn()
initialNumber = participants.size()
percentStillIn = int(round(100 * numberStillIn / initialNumber, 0))


# print "There are currently **" + str(numberStillIn) + " out of " + str(initialNumber) +"** original participants.  That's **" + str(int(round(100*numberStillIn/initialNumber,0))) + "%**  Here is the list of participants still with the challenge:\n"

def stringToPrintLegacy():
    answer = "There are currently **NUMBER_STILL_IN out of INITIAL_NUMBER** original participants.  That's **PERCENT_STILL_IN%**.  Here is the list of participants still with the challenge:\n\n"
    answer = re.sub('NUMBER_STILL_IN', str(numberStillIn), answer)
    answer = re.sub('INITIAL_NUMBER', str(initialNumber), answer)
    answer = re.sub('PERCENT_STILL_IN', str(percentStillIn), answer)
    for participant in participants.participantsWhoAreStillIn():
        answer += "/u/" + participant.name
        if not participant.hasCheckedIn:
コード例 #16
0
ファイル: checkin.py プロジェクト: foobarbazblarg/stayclean
#!/usr/bin/env python3
import sys
from participantCollection import ParticipantCollection

if __name__ == "__main__":
    names = sys.argv[1::]
    participants = ParticipantCollection()
    for name in names:
        if participants.hasParticipantNamed(name):
            participants.participantNamed(name).hasCheckedIn = True
            print(f"just checked in {name}")
        else:
            print(f"*** WARNING: {name} is not present in participants.txt")
    participants.save()
コード例 #17
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(
コード例 #18
0
ファイル: relapse.py プロジェクト: foobarbazblarg/stayclean
#!/usr/bin/python
import sys
from participantCollection import ParticipantCollection


names = sys.argv[1::]

participants = ParticipantCollection()
for name in names:
    if participants.hasParticipantNamed(name):
        participant = participants.participantNamed(name)
        if participant.isStillIn:
            participant.relapseNowIfNotAlready()
            print "just relapsed " + name
        else:
            print name + " has already relapsed.  Skipping."
    else:
        print "*** WARNING: " + name + " is not present in participants.txt"
participants.save()