fork download
  1. import re
  2.  
  3. class FindSpam:
  4. rules = [
  5. {'regex': "(?i)\\b(baba(ji)?|nike|vashikaran|sumer|kolcak|porn|molvi|judi bola|ituBola.com|lost lover|11s)\\b", 'all': True,
  6. 'sites': [], 'reason': "Bad keyword detected"},
  7. {'regex': "\\+\\d{10}|\\+?\\d{2}[\\s\\-]?\\d{8,10}", 'all': True,
  8. 'sites': ["patents.stackexchange.com"], 'reason': "Phone number detected"},
  9. {'regex': "(?i)\\b(nigg?(a|er)|asshole|crap|fag|fuck(ing?)?|idiot|shit|whore)s?\\b", 'all': True,
  10. 'sites': [], 'reason': "Offensive title detected",'insensitive':True},
  11. {'regex': "^(?=.*[A-Z])[^a-z]*$", 'all': True, 'sites': [], 'reason': "All-caps title"}
  12. ]
  13.  
  14. @staticmethod
  15. def testpost(title, site):
  16. result = [];
  17. for rule in FindSpam.rules:
  18. if rule['all'] != (site in rule['sites']):
  19. if re.compile(rule['regex']).search(title):
  20. result.append(rule['reason'])
  21. return result
  22.  
  23. names = '''JYTHON HELP PLEASE I DONT KNOW WHERE I AM GOING WORNG :(
  24. JYTHON HELP PLEASE....I I DONT KNOW WHERE I AM GOING WORNG :(
  25. JYTHON HELP PLEASE DONT KNOW WHERE I AM GOING WORNG :(
  26. HELP PLS… I AM STUCK R4WR'''
  27.  
  28. for name in re.split(r'\n', names):
  29. print name
  30. print FindSpam.testpost(name, "stackoverflow.com")
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
JYTHON HELP PLEASE I DONT KNOW WHERE I AM GOING WORNG :(
['All-caps title']
JYTHON HELP PLEASE....I I DONT KNOW WHERE I AM GOING WORNG :(
['All-caps title']
JYTHON HELP PLEASE DONT KNOW WHERE I AM GOING WORNG :(
['All-caps title']
HELP PLS… I AM STUCK R4WR
['All-caps title']