Beeminding Markdown Folders (Obsidian)

Hi all
I was looking into ways of beeminding my Obsidian vault but the current beeminding word count, the urlminder and the github integration don’t currently work for my purposes at the moment.
I was wondering whether anyone knew a way (maybe with an integration, automation service or something else) that would:

  1. Count the number of documents in a particular folder (whether on an online storage place or on desktop)
  2. Count the number of times a key phrase is used in a folder area (in my case this would be [ x ] to track completed todo items but for others it could be another term)

Many thanks for your help!

1 Like

You can ask ChatGPT to write you a script that will find all matches in a folder and report their count to Beeminder using API.

For macOS/Linux you need to ask it for a Bash script, and if you’re on Windows you want Powershell.

Then you will need to find a program that can run a script every day. On macOS you can likely do it with the built-in Automator. No idea for other OSes unfortunately, but ChatGPT is actually better than Google at recommending software, in my experience.

If you haven’t done programming before, it will involve a bit of trial and error, but the good thing is that you can’t mess it up too much. Most likely you’ll just get wrong counts for the first version of the script and then you’ll ask ChatGPT to fix it and it’ll start working after a few iterations.

4 Likes

There is also a Beeminder integration that you can find on the Obsidian store. It just counts words when you execute a command; so it won’t fit your purpose, but it’s still noteworthy :slightly_smiling_face:

3 Likes

For scheduling tasks on Windows, I use “schtasks”. It’s built in to Windows, runs from the command line, and works pretty well in my experience.

4 Likes

This sounds super valuable. Sanity check: Is there anything Obsidian-specific here? Beeminding number of files in a folder or number of occurrences of a hashtag or regex in a set of files sounds pretty universal!

Do share any scripts you end up using!

3 Likes

Hi All
After suggestion from @april I had a conversation with chatgpt which created me the code that I needed to create python files for number of files and number of times the keyterm - [ x ] appears.

Here is the number of files in a folder code

expand for Number of files in folder code
import os
import requests
import datetime
import pymsgbox

# Beeminder API configuration
USERNAME = 'your_username'
GOAL = 'your_goal'
AUTH_TOKEN = 'your_auth_token'

# Folder path
folder_path = input("Enter the folder path: ")

# Retrieve previous count from the file
previous_count = 0
today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)
file_path = f'file_count_{yesterday}.txt'

if os.path.exists(file_path):
    with open(file_path, 'r') as file:
        previous_count = int(file.read())

# Count the number of documents in the folder
current_count = sum(1 for _ in os.scandir(folder_path) if _.is_file())

# Calculate the difference
difference = current_count - previous_count

# Update the count file with the current count
with open(f'file_count_{today}.txt', 'w') as file:
    file.write(str(current_count))

# Send the difference to the Beeminder API
url = f'https://www.beeminder.com/api/v1/users/{USERNAME}/goals/{GOAL}/datapoints.json'
data = {'auth_token': AUTH_TOKEN, 'value': difference}
response = requests.post(url, data=data)

if response.status_code == 200:
    pymsgbox.alert('Data successfully sent to Beeminder!', 'Success')
else:
    pymsgbox.alert('Failed to send data to Beeminder.', 'Error')

and here is the code for keyterms appearing in the requested folder

expand for number of times keyword is used in folder code
import os
import requests
import datetime
import pymsgbox
from tqdm import tqdm

# Beeminder API configuration
USERNAME = 'your_username'
GOAL = 'your_goal'
AUTH_TOKEN = 'your_auth_token'

# Folder path
folder_path = input("Enter the folder path: ")

# Retrieve previous count from the file
previous_count = 0
today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)
file_path = f'count_{yesterday}.txt'

if os.path.exists(file_path):
    with open(file_path, 'r') as file:
        previous_count = int(file.read())

# Count the occurrences of "- [x]" in Markdown files
count = 0
file_count = 0

for root, dirs, files in os.walk(folder_path):
    for file in files:
        if file.endswith('.md'):
            file_count += 1

pbar = tqdm(total=file_count, desc='Progress', unit='file')

for root, dirs, files in os.walk(folder_path):
    for file in files:
        if file.endswith('.md'):
            file_path = os.path.join(root, file)
            with open(file_path, 'r', encoding='utf-8') as f:
                content = f.read()
                count += content.count('- [x]')
            pbar.update(1)

pbar.close()

# Calculate the difference
difference = count - previous_count

# Update the count file with the current count
with open(f'count_{today}.txt', 'w') as file:
    file.write(str(count))

# Send the difference to the Beeminder API
url = f'https://www.beeminder.com/api/v1/users/{USERNAME}/goals/{GOAL}/datapoints.json'
data = {'auth_token': AUTH_TOKEN, 'value': difference}
response = requests.post(url, data=data)

if response.status_code == 200:
    pymsgbox.alert('Data successfully sent to Beeminder!', 'Success')
else:
    pymsgbox.alert('Failed to send data to Beeminder.', 'Error')

@dreev As Obsidian is built on markdown files for the most part, this code should be usable for any folder. The first one counting number of files should work for any folder I think. The keyterm code however I think I may have instructed for the find keyterm code to specifically work for markdown files only…

UPDATE: spoke to Chatgpt and it gave me updated code to allow for any file in a folder.

updated keyterm code
import os
import requests
import datetime
import pymsgbox
from tqdm import tqdm

# Beeminder API configuration
USERNAME = 'your_username'
GOAL = 'your_goal'
AUTH_TOKEN = 'your_auth_token'

# Folder path
folder_path = input("Enter the folder path: ")

# Retrieve previous count from the file
previous_count = 0
today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)
file_path = f'count_{yesterday}.txt'

if os.path.exists(file_path):
    with open(file_path, 'r') as file:
        previous_count = int(file.read())

# Count the occurrences of "- [x]" in all files in the folder
count = 0
file_count = 0

for root, dirs, files in os.walk(folder_path):
    file_count += len(files)

pbar = tqdm(total=file_count, desc='Progress', unit='file')

for root, dirs, files in os.walk(folder_path):
    for file in files:
        file_path = os.path.join(root, file)
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()
            count += content.count('- [x]')
        pbar.update(1)

pbar.close()

# Calculate the difference
difference = count - previous_count

# Update the count file with the current count
with open(f'count_{today}.txt', 'w') as file:
    file.write(str(count))

# Send the difference to the Beeminder API
url = f'https://www.beeminder.com/api/v1/users/{USERNAME}/goals/{GOAL}/datapoints.json'
data = {'auth_token': AUTH_TOKEN, 'value': difference}
response = requests.post(url, data=data)

if response.status_code == 200:
    pymsgbox.alert('Data successfully sent to Beeminder!', 'Success')
else:
    pymsgbox.alert('Failed to send data to Beeminder.', 'Error')
3 Likes