Raised This Month: $51 Target: $400
 12% 

[TOOLS][Python] Remove SourceTV demos older than 5 days


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
th7nder
Senior Member
Join Date: Oct 2014
Old 08-06-2015 , 15:18   [TOOLS][Python] Remove SourceTV demos older than 5 days
Reply With Quote #1

Hi guys! I've recently made a python script, to remove old sourcetv/hltv records, because who needs records older than 5 days? It's script to those people who have their own dedicated server/VPS in every other case i'm sure that your hosting provider is doing it for you (;


It's reading date in format from csgo_demo_crash_fix plugin, in every other case it might not work so u're using it on your own risk (;

Code:
import os
import datetime

demos_directory = "/home/codmod/game/server/csgo/demos/"
now = datetime.datetime.now()
for file in os.listdir(demos_directory):
	if file.find(".dem") == -1 or file.find("auto") == -1:
		continue
		
	splitted = file.split("-")
	date = splitted[1]
	year = date[:4]
	month = date[4:6]
	day = date[6:8]
	
	datetime_instance = datetime.datetime(int(year), int(month), int(day), 0, 0)
	diff = now - datetime_instance
	if(diff.days > 5):
		os.remove(demos_directory + file)
All you have to do is:
1. Make python file and upload it on your dedicated server, name it like you like, for example: delete_demos.py and put in /home/csgo/
2. Change path in variable demos_directory to yours, where your demos are stored,
3. chmod +x /home/csgo/delete_demos.py
4. crontab -e
5. write record in crontab like: */5 * * * * python /home/csgo/delete_demos.py
6. voila, your demos are gonna be deleted in every 5 minutes, when they are older than 5 days.

Last edited by th7nder; 08-06-2015 at 15:21.
th7nder is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 08-06-2015 , 17:39   Re: [TOOLS][Python] Remove SourceTV demos older than 5 days
Reply With Quote #2

Or if you are on linux:

Code:
find /path/ -type f -name "*.dem" -mtime +5 -delete
__________________
Stopped hosting servers as of November 2018, no longer active around here.

Last edited by pcmaster; 08-06-2015 at 17:39.
pcmaster is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 08-10-2015 , 23:34   Re: [TOOLS][Python] Remove SourceTV demos older than 5 days
Reply With Quote #3

Thanks for sharing. Alternately, I made a SM plugin to do just that a long time back:
https://forums.alliedmods.net/showthread.php?t=236027

Then, new server managers dont need to learn to use crontab and to chmod (although they should probably learn that anyways...). I have a more recent version (that one is 1.5 yrs old) that i'll upload soon (my wedding is in 5 days, so I'll do it later when I have time to update documentation, etc.). According to the changelog, here is the only difference between it and the above version (or at least that I remembered to write down):
Code:
v4.0:
	* Started Change log.
	* Coded in ability to move stuff, made days a float instead of an integer, gave option to accept "any" file extension
An example from the 4.0 version of how it could be configured for demos:
Spoiler


I'll try to get 4.0 on the website sometime in the next few weeks (I may need to be reminded after my wedding).
__________________

Last edited by ThatOneGuy; 08-10-2015 at 23:37.
ThatOneGuy is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 08-12-2015 , 19:58   Re: [TOOLS][Python] Remove SourceTV demos older than 5 days
Reply With Quote #4

i think in windows you can use forfiles
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 08-28-2015 , 10:53   Re: [TOOLS][Python] Remove SourceTV demos older than 5 days
Reply With Quote #5

Quote:
Originally Posted by ThatOneGuy View Post
(I may need to be reminded after my wedding).
Congratulations!

Spoiler
Potato Uno is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 08-29-2015 , 02:01   Re: [TOOLS][Python] Remove SourceTV demos older than 5 days
Reply With Quote #6

Quote:
Originally Posted by Potato Uno View Post
Congratulations!

Spoiler
Updated: https://forums.alliedmods.net/showth...15#post2104415
__________________
ThatOneGuy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:43.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode