mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-02-17 13:58:11 +00:00
Added database cleanup (untested)
This commit is contained in:
parent
7ffa81ffbd
commit
dada20d0b9
3
LICENSE
3
LICENSE
|
@ -9,6 +9,3 @@ This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
33
twoot.py
33
twoot.py
|
@ -34,6 +34,9 @@ from mastodon import Mastodon, MastodonError, MastodonAPIError, MastodonIllegalA
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
# Number of records to keep in db table for each twitter account
|
||||||
|
MAX_REC_COUNT = 50
|
||||||
|
|
||||||
NITTER_URLS = [
|
NITTER_URLS = [
|
||||||
'https://nitter.42l.fr',
|
'https://nitter.42l.fr',
|
||||||
'https://nitter.pussthecat.org',
|
'https://nitter.pussthecat.org',
|
||||||
|
@ -510,10 +513,10 @@ def main(argv):
|
||||||
logging.info(str(in_db_cnt) + ' tweets already in database')
|
logging.info(str(in_db_cnt) + ' tweets already in database')
|
||||||
|
|
||||||
# DEBUG: Print extracted tweets
|
# DEBUG: Print extracted tweets
|
||||||
#for t in tweets:
|
# for t in tweets:
|
||||||
#print(t)
|
# print(t)
|
||||||
|
|
||||||
# Login to account on maston instance
|
# Login to account on maston instance
|
||||||
mastodon = None
|
mastodon = None
|
||||||
if len(tweets) != 0:
|
if len(tweets) != 0:
|
||||||
mastodon = login(mast_instance, mast_account, mast_password)
|
mastodon = login(mast_instance, mast_account, mast_password)
|
||||||
|
@ -598,6 +601,30 @@ def main(argv):
|
||||||
except FileNotFoundError: # The directory does not exist
|
except FileNotFoundError: # The directory does not exist
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Evaluate excess records in database
|
||||||
|
excess_count = 0
|
||||||
|
|
||||||
|
db.execute('SELECT count(*) FROM toots WHERE twitter_account=?', (twit_account,))
|
||||||
|
db_count = db.fetchone()
|
||||||
|
if db_count is not None:
|
||||||
|
excess_count = db_count[0] - MAX_REC_COUNT
|
||||||
|
|
||||||
|
# Delete excess records
|
||||||
|
if excess_count > 0:
|
||||||
|
db.execute('''
|
||||||
|
WITH excess AS (
|
||||||
|
SELECT tweet_id
|
||||||
|
FROM toots
|
||||||
|
WHERE twitter_account=?
|
||||||
|
ORDER BY timestamp ASC
|
||||||
|
LIMIT ?
|
||||||
|
)
|
||||||
|
DELETE from toots
|
||||||
|
WHERE tweet_id IN excess''', (twit_account, excess_count))
|
||||||
|
sql.commit()
|
||||||
|
|
||||||
|
logging.debug('Deleted ' + str(excess_count) + ' records from database.')
|
||||||
|
|
||||||
logging.info('Run time : %2.1f seconds' % (time.time() - start_time))
|
logging.info('Run time : %2.1f seconds' % (time.time() - start_time))
|
||||||
logging.info('_____________________________________________________________________________________')
|
logging.info('_____________________________________________________________________________________')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user