示例#1
0
	def schedule_new_submission(self):
		# Attempt to schedule a new submission
		# Check that one has not been completed or in the process of, before submitting

		# Filters for Things which have been submitted successfully or
		# that are in the process of (ie attempts counter has not maxed out)
		recent_submissions = list(db_Thing.select(db_Thing).where((db_Thing.posted_name.is_null(False)) | (db_Thing.text_generation_attempts < 3 & db_Thing.reddit_post_attempts < 1)).
					where(fn.Lower(db_Thing.subreddit) == self._subreddit.lower()).
					where(db_Thing.source_name == 't3_new_submission').
					where((datetime.timestamp(datetime.utcnow()) - db_Thing.created_utc) < self._new_submission_frequency.total_seconds()))

		if recent_submissions:
			# There was a submission recently so we cannot proceed.
			return

		logging.info(f"Scheduling a new submission on {self._subreddit}")

		new_submission_thing = {}

		new_submission_thing['source_name'] = 't3_new_submission'
		new_submission_thing['subreddit'] = self._subreddit

		text_generation_parameters = self._default_text_generation_parameters.copy()
		text_generation_parameters['prompt'] = self._get_random_new_submission_tag()
		text_generation_parameters['max_length'] = 1000

		new_submission_thing['text_generation_parameters'] = text_generation_parameters

		return db_Thing.create(**new_submission_thing)
示例#2
0
	def insert_praw_thing_into_database(self, praw_thing, text_generation_parameters=None):
		record_dict = {}
		record_dict['source_name'] = praw_thing.name

		if text_generation_parameters:
			# If we want to generate a text reply, then include these parameters in the record
			record_dict['text_generation_parameters'] = text_generation_parameters

		return db_Thing.create(**record_dict)