<commit_before># Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""A reddit bot to detect which actions subreddit moderators actually took."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
from datetime import datetime, timedelta
import json
import os
import praw
import time
import sys

import log_subreddit_comments
import moderate_subreddit


# approved, removed, and deleted columns are booleans. 'approved' is only
# present when the bot is a mod.
APPROVED_COL = 'approved'
REMOVED_COL = 'removed'
DELETED_COL = 'deleted'
# score, ups, and downs refer to user votes. in practice, it appears that
# 'downs' is always 0 and 'score' == 'ups'. (this may be different if the bot is
# a mod.)
SCORE_COL = 'score'
UPS_COL = 'ups'
DOWNS_COL = 'downs'
SCORE_HIDDEN_COL = 'score_hidden'
# collapsed is a boolean. it appears to be true when the comment (and all its
# children) are collapsed in the UI. this most commonly happens when the comment
# is deleted or removed, but it also seems to happens when the comment has more
# downvotes
COLLAPSED_COL = 'collapsed'

FILENAME_OUTPUT_PREFIX = 'modactions'


def write_moderator_actions(reddit,
                            record,
                            id_key,
                            timestamp_key,
                            output_path,
                            hours_to_wait,
                            has_mod_creds):
  create_time_utc = datetime.strptime(record[timestamp_key], <KEY>')
  check_time_utc = create_time_utc + timedelta(hours=hours_to_wait)
  wait_until(check_time_utc)

  record['action_checked_utc'] = log_subreddit_comments.now_timestamp()
  status_fields = fetch_reddit_comment_status(reddit, record[id_key],
                                              has_mod_creds)
  if status_fields is not None:
    record.update(status_fields)

  log_subreddit_comments.append_records(output_path, [record])

<commit_msg>Document score_hidden field.<commit_after># Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""A reddit bot to detect which actions subreddit moderators actually took."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
from datetime import datetime, timedelta
import json
import os
import praw
import time
import sys

import log_subreddit_comments
import moderate_subreddit


# approved, removed, and deleted columns are booleans. 'approved' is only
# present when the bot is a mod.
APPROVED_COL = 'approved'
REMOVED_COL = 'removed'
DELETED_COL = 'deleted'
# score, ups, and downs refer to user votes. in practice, it appears that
# 'downs' is always 0 and 'score' == 'ups'. (this may be different if the bot is
# a mod.)
SCORE_COL = 'score'
UPS_COL = 'ups'
DOWNS_COL = 'downs'
# score_hidden is a boolean for when the above score-related fields are hidden
# due to subreddit rules. with a sufficient hours_to_wait delay, this shouldn't
# be true for the checked comments.
SCORE_HIDDEN_COL = 'score_hidden'
# collapsed is a boolean. it appears to be true when the comment (and all its
# children) are collapsed in the UI. this most commonly happens when the comment
# is deleted or removed, but it also seems to happens when the comment has more
# downvotes
COLLAPSED_COL = 'collapsed'

FILENAME_OUTPUT_PREFIX = 'modactions'


def write_moderator_actions(reddit,
                            record,
                            id_key,
                            timestamp_key,
                            output_path,
                            hours_to_wait,
                            has_mod_creds):
  create_time_utc = datetime.strptime(record[timestamp_key], '%Y%m%d_%H%M%S')
  check_time_utc = create_time_utc + timedelta(hours=hours_to_wait)
  wait_until(check_time_utc)

  record['action_checked_utc'] = log_subreddit_comments.now_timestamp()
  status_fields = fetch_reddit_comment_status(reddit, record[id_key],
                                              has_mod_creds)
  if status_fields is not None:
    record.update(status_fields)

  log_subreddit_comments.append_records(output_path, [record])


{'fraction_non_alphanumeric': 0.06476336462923932, 'fraction_numerical': 0.0034489365778884846, 'mean_word_length': 3.4050632911392404, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1778312', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1460, 'n_words': 561}