SHARE
TWEET

Untitled

a guest Dec 23rd, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2. #
  3. # Execute via ctrontab:
  4. #  */10 *  * * * mattermost  /opt/mattermost/mmdel.py
  5.  
  6.  
  7. import psycopg2
  8. import os
  9.  
  10. datadir = "/opt/mattermost/data"
  11. # Try to connect
  12.  
  13. try:
  14.     conn=psycopg2.connect(database="mattermost", user="mattermost", password="PASSWORD", host="localhost")
  15. except Exception as e:
  16.     print ("I am unable to connect to the database." + str(e))
  17.  
  18. cur = conn.cursor()
  19. try:
  20.     cur.execute("""SELECT path, posts.deleteat
  21.                 FROM fileinfo
  22.                 INNER JOIN posts ON fileinfo.postid=posts.id
  23.                 WHERE posts.deleteat > 0;""")
  24. except Exception as e:
  25.     print ("Select failed" + str(e))
  26.  
  27. rows = cur.fetchall()
  28. for row in rows:
  29.     fileName = os.path.join(datadir, row[0])
  30.     if(os.path.isfile(fileName)):
  31.         print ("deleting ", fileName)
  32.         os.remove(fileName)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top