コード例 #1
0
	def extract_code(self,regExMain,regExRemove):

		#expression with coupon code
		exp = re.search(regExMain,self.tweet)

		if not exp: return None

		#if pattern match was found, remove words 'coupon code' and extract just the code
		answer = exp.group(0)
		answer = ' '.join([word for word in answer.split() if word.lower() not in stopwords.stopwords])
		if 'Expires' in answer or 'ends' in answer:
			print answer

		code = re.sub(regExRemove,'',answer)

		#trimquotes
		code = Utilities.trimquotes(code)

		if code.isdigit() or code == '' or code.lower() in stopwords.stopwords:
			return 

		return code