Java that displays text fash cards from my notes / kindle clippings
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Hi there,

I would like some java code (or recommend?) that runs and shows me text only flash cards based on information from my "My Clippings" kindle reader file as well as a ideas.txt file that is a plain text file that I keep with random ideas I get (one idea per line).

It should work on Linux Mint Cinnamon 18.

Simply I will run it a few times a day using cron and it will open and show me a random kindle clipping or line from my ideas.txt file. I will then have three buttons to choose from:

Do not show again for at least: [2 days] [1 week] [1 month] [3 months] [Never]

Every time I choose a button above it will move onto another random clipping or idea. It will do this until I close the app.

It must take into consideration that the My Clippings files and ideas.txt will be updated frequently.

Hope this is clear :)

awarded to w40ut

Crowdsource coding tasks.

2 Solutions

First find your clipping file (usually in kindle root directory or whatever kindle is). Second, rename it to "Clippings.txt", and put it on same path as the script. ----- If you want to do the same to an ideas.txt file you just need to rename on the line :

clippings = readClippings("Clippings.txt")

"Clippings.txt" to "ideas.txt"


Code in python 3:

#!/usr/bin/env python3

import cgi
import random

def readClippings(filename):
  separator = "=========="
  blocks    = [[]]

  with open(filename) as f:
    for line in f:
      line = line.rstrip()
      line = line.replace("\ufeff", "") # Replace broken BOM

      if line == separator:

  return blocks

def splitClipping(clipping):
  publication = clipping[0]
  quote       = ""

  for line in clipping[2:]:
    quote = quote + line

  return publication, quote

if __name__ == "__main__":

  print("Content-type: text/html; charset=UTF-8")

  clippings = readClippings("Clippings.txt")
  clippings = [splitClipping(x) for x in clippings]
  clippings = [(x,y) for x,y in clippings if y]

  publication, quote = random.choice(clippings)

  <title>Spark: A random quote from Kindle clippings</title>

</p>""" % cgi.escape(quote))

<p style="text-align:right">
  &mdash; %s
""" % cgi.escape(publication))

Thanks so much. That was fast! Does this have the following features I asked for? Asking me; Do not show again for at least: [2 days] [1 week] [1 month] [3 months] [Never] Right now it shows me HTML. Is there a special way I should run this so that it renders in a browser? Thanks again.
martinr over 6 years ago
Also - Any chance it can take info from both files at once so that I don't have to run this twice (once for ideas.txt and once for Clippings.txt)?
martinr over 6 years ago
Yes. I'll make that! Give me some minutes! :)
w40ut over 6 years ago
Just found this phyton code that splits each clip and converts it to HTML page (so you can open it on browser). You can also search by author and book!
w40ut over 6 years ago
Thanks W40ut, this looks good. I installed it but get errors when I try to run it. I don't think this is really what I need however. I wanted something as per my original post. It is to randomly remind me of things that I have placed in my clippings / notes. Not sure if it can be combined somehow with Whoarder? Or have I misunderstood something? I think Whoarder will show me my entire clippings file which I dont really want. Also doesnt include my ideas.txt.
martinr over 6 years ago
whoarder "My Clippings.txt" Traceback (most recent call last): File "/usr/local/bin/whoarder", line 19, in clippings = Clippings(args.source, args.destination) File "/usr/local/lib/python2.7/dist-packages/whoarder/", line 17, in init self.fetch() File "/usr/local/lib/python2.7/dist-packages/whoarder/", line 33, in _fetch clippings = ClippingsIterator(self.source) File "/usr/local/lib/python2.7/dist-packages/whoarder/", line 89, in _init__ self.sourcefile = open(source, mode='r', encoding=detectedencoding) TypeError: 'encoding' is an invalid keyword argument for this function
martinr over 6 years ago
Are you still helping with this w4Out?
martinr over 6 years ago
Winning solution

Ok so you need this:

After you got the output (myclippings.txt) separated each clipping by "---" (the python program do that for you) create a folder and create a file called "index.html". After that create a folder inside the first folder and choose the name "clippings" (per example..) and paste your "myclippings.txt" and your "ideas.txt"


Index.html - Made this quick html/php file that has 2 buttons (1 and 2). 1 gets a random clip from your myclippings.txt and 2 gets a random clip from ideas.txt.

<!DOCTYPE html>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type="submit" name="random" value="1"> <input type="submit" name="random2" value="2">


$file = 'clippings/myclippings.txt';
$fp = @fopen($file, "r");
if ($fp) {
   $array = explode("---", fread($fp, filesize($file)));

$file2 = 'clippings/ideas.txt';
$fp2 = @fopen($file2, "r");
if ($fp2) {
   $array2 = explode("---", fread($fp2, filesize($file2)));
$count = count($array);
$count2 = count($array2);
$rand = rand(0,$count);
$rand2 = rand(0,$count2);
if($rand == $count)
$rand -=1;
if($rand2 == $count2)
$rand2 -=1;

 $name = $_POST['random']; 
    if ($name == '1') {
        echo '<br>';
        echo $array[$rand];
    } else {
        echo '<br>';
        echo $array2[$rand2];



Thanks for this. So is this part not possible then? "Do not show again for at least: [2 days] [1 week] [1 month] [3 months] [Never]"?
martinr over 6 years ago
Well not really because you would need a database.. And a little more of code! :p Even if i had a variable to count days, it just doesnt make sense.. everytime you refresh or something the code is re-loaded.. so no database where data is stored permanently.
w40ut over 6 years ago
@martinr sorry but i can't do better... :(
w40ut over 6 years ago
View Timeline