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')