Comments (10)
One issue I think I will run into is having a very large file (thousands of links). Perhaps links older than 1 month are not saved
from rtv.
Also, I'm not too sure about log file standards. Would it be okay to put it in .config/rtv/history.log
?
from rtv.
From what I can find it either needs to go in XDG_CACHE_HOME
or XDG_DATA_HOME
. It's unclear to me which one is correct, but I would lean towards CACHE because it's non-essential data. I would also name the file history.txt
because it's not a standard log in the sense that it will be consumed and overwritten by the program.
Using timestamps for each link sounds like a lot of overhead, it might be better to just save the most recent N links.
from rtv.
To save the most recent N links, we would have to use some sort of ordered list. A set is unordered so restricting the size of it when writing would not guarantee that you would get the last N links, just N random links.
Would you be opposed to refactoring to use a list instead? That way we could just slice the end of the list for the output file.
Also, is 1000 a reasonable number of links to save?
from rtv.
I used a set because testing for membership is O(1) as opposed to lists which are O(N). I don't think going back to a list is a good idea. Also think about how you're going to write to this file. If you only write when the program is quit via q
, you will be losing history on ctrl-c
.
Here's one approach that uses file appends to avoid having to overwrite the whole file after each time. There may be other approaches as well.
- Read the file in as a list.
- If the list length is over N, overwrite the file with only the most recent N links.
- Convert the list to a set
- When a new link is clicked, add it to the set AND append the link directly to the end of the file.
As for the number of links, I think 100-200 would probably be enough.
from rtv.
Good point about the complexity. I like this approach. It has lot of extra file operations, but I guess that's necessary to not lose history if you quit with ctrl+c
.
from rtv.
As for the ctrl+c
problem, why not use atexit
?
import atexit
import time
@atexit.register
def save():
print('saving')
if __name__ == '__main__':
time.sleep(2)
print('done')
run this, no matter what (ctrl+c, or normal exit), "saving" will always be printed.
from rtv.
Didn't know that module existed! Sounds good to me. If we use that, I think it would be best to do the file I/O at exit instead of when you visit each link. It would keep the code cleaner.
from rtv.
I've got an implementation working. @michael-lazar, it is very similar to how you described it, except it uses the a@atexit
decorator to do one file operation at exit instead of loading and writing to the file all of the time. See #95
from rtv.
Merged in #95
from rtv.
Related Issues (20)
- add Twitch mime parser HOT 5
- Crash when hitting G on empty thread HOT 1
- RTV development is shutting down HOT 30
- Offering to help with the project HOT 1
- ConnectionError upon first launch
- no confirmation on exit HOT 1
- Program exited with status 127 HOT 1
- When you set $RTV_BROWSER variable to a program with options like "mybrowser -u" it basicly doesn't work HOT 1
- [1.2.7] Where is the configuration option to toggle whether to open web browser links in a new tab or a new window?
- Not being able to view remote image url via iTerm2's imgcat HOT 6
- How do I change it that rtv uses leafpad instead of nano as its default text editor?
- Save option for posts.
- Option to edit a posted comment.
- Where does rtv store the credentials or session/cookie file so I could just take a rtv install to another OS/new install and donβt have to reopen Firefox for allowing the app access?
- Version 1.27.0_1 (from brew) crashed when opening url HOT 5
- Fix incase mpv is not opening anymore
- When pressing < o > key on a reddit post rtv crashes, "Can't pickle local object" HOT 1
- Crash while trying to sign in HOT 1
- Crash while trying to open a submission link HOT 2
- Archiving Github Repository
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rtv.