Skip to content

Commit

Permalink
Added a directory to find tasks in markdown files
Browse files Browse the repository at this point in the history
  • Loading branch information
emilmerle committed Jan 22, 2024
1 parent 0c7bb63 commit 7bc71ee
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 50 deletions.
6 changes: 3 additions & 3 deletions alliterations/alliterationInClipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def main():
matches.append(alliterations)

if len(matches) > 0:
pyperclip.copy(' -+- '.join(matches))
pyperclip.copy(" -+- ".join(matches))
print("Alliteration(s) found:")
print('\n'.join(matches))
print("\n".join(matches))
else:
print('No alliteration found.')
print("No alliteration found.")


if __name__ == "__main__":
Expand Down
13 changes: 6 additions & 7 deletions alliterations/alliterationInFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ def main():
try:
argumentOne = sys.argv[1]
except IndexError:
exit("No second argument given. "
"Try again with a file path as an argument")
exit("No second argument given. " "Try again with a file path as an argument")

# Make absolute path if given path is a relative path
if(not os.path.isabs(argumentOne)):
if not os.path.isabs(argumentOne):
argumentOne = os.path.abspath(argumentOne)

openedContent = ""

# Check if argumentOne is a valid path and file
if(os.path.exists(argumentOne) and os.path.isfile(argumentOne)):
if os.path.exists(argumentOne) and os.path.isfile(argumentOne):
# Try to open and read file
try:
openedFile = open(argumentOne, "r")
Expand All @@ -43,11 +42,11 @@ def main():
openedFile.close()

if len(matches) > 0:
pyperclip.copy(' -+- '.join(matches))
pyperclip.copy(" -+- ".join(matches))
print("Alliteration(s) found:")
print('\n'.join(matches))
print("\n".join(matches))
else:
print('No alliteration found.')
print("No alliteration found.")


if __name__ == "__main__":
Expand Down
7 changes: 5 additions & 2 deletions emailAdresses/email.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import re


regexp = re.compile(r'''(
regexp = re.compile(
r"""(
[a-zA-Z0-9._%+-]+ # username
@ # @ symbol
(\w)+ # domain name
(\.[a-zA-Z]{2,4}) # dot-something
)''', re.VERBOSE)
)""",
re.VERBOSE,
)
6 changes: 3 additions & 3 deletions emailAdresses/emailInClipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def main():
matches.append(emails)

if len(matches) > 0:
pyperclip.copy(' -+- '.join(matches))
pyperclip.copy(" -+- ".join(matches))
print("Email address(es) found:")
print('\n'.join(matches))
print("\n".join(matches))
else:
print('No email address found.')
print("No email address found.")


if __name__ == "__main__":
Expand Down
13 changes: 6 additions & 7 deletions emailAdresses/emailInFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ def main():
try:
argumentOne = sys.argv[1]
except IndexError:
exit("No second argument given. "
"Try again with a file path as an argument")
exit("No second argument given. " "Try again with a file path as an argument")

# Make absolute path if given path is a relative path
if(not os.path.isabs(argumentOne)):
if not os.path.isabs(argumentOne):
argumentOne = os.path.abspath(argumentOne)

openedContent = ""

# Check if argumentOne is a valid path and file
if(os.path.exists(argumentOne) and os.path.isfile(argumentOne)):
if os.path.exists(argumentOne) and os.path.isfile(argumentOne):
# Try to open and read file
try:
openedFile = open(argumentOne, "r")
Expand All @@ -43,11 +42,11 @@ def main():
openedFile.close()

if len(matches) > 0:
pyperclip.copy(' -+- '.join(matches))
pyperclip.copy(" -+- ".join(matches))
print("Email address(es) found:")
print('\n'.join(matches))
print("\n".join(matches))
else:
print('No email address found.')
print("No email address found.")


if __name__ == "__main__":
Expand Down
Empty file added markdownTasks/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions markdownTasks/taskInFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! python3
# taskInFile.py - Finds tasks in a given markdown file, prints them to the terminal and copys them to the clipboards
# Usage: call the program with a file path as the first argument
# Example: >>> taskInFile.py C:\\Users\\ExampleUser\\Documents\\myTasks.md


# import pyperclip
import sys
import os


def main():
# Check if sys.argv[1] is given
argumentOne = ""
try:
argumentOne = sys.argv[1]
except IndexError:
exit("No argument given. Try again with a file path as an argument")

# Make absolute path if given path is a relative path
if not os.path.isabs(argumentOne):
argumentOne = os.path.abspath(argumentOne)

files = os.listdir(argumentOne)

for file in files:
if file.endswith(".md"):
handleFile(argumentOne + "\\" + file)


def handleFile(markdownFile: str):
with open(markdownFile, "r") as f:
for line in f:
if "!!!" in line:
print(f"Task in line found: {line[:-1]}")


if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions markdownTasks/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Header 1
## Header 2
- test
# Header 3
- task !!!
- Unteraufgabe
- Task Unter!!!
10 changes: 5 additions & 5 deletions phoneNumbers/countries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

countryDict = {
'canada': r'''
"canada": r"""
((\+?1)?) # country code
(\s|-|\.)? # separator
(\([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]\))? # area code
Expand All @@ -13,12 +13,12 @@
([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2}) # first three
(\s|-|\.)? # separator
(\d{4}) # last four (required)
''',
'germany': r'''(
""",
"germany": r"""(
(\d{3}|\(\d{3}\))? # area code (optional)
(\s|-|\.|/)? # separator (optional)
(\d{7,9}) # 7 to 9 digits
)'''
)""",
}

countryDict['usa'] = countryDict.get('canada')
countryDict["usa"] = countryDict.get("canada")
20 changes: 9 additions & 11 deletions phoneNumbers/numberInFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ def main():
try:
argumentOne = sys.argv[1]
except IndexError:
exit("No argument given."
" Try again with a country as an argument")
exit("No argument given." " Try again with a country as an argument")

if(argumentOne in countryDict):
if argumentOne in countryDict:
# Create regex object
regexCompile = re.compile(countryDict[argumentOne], re.VERBOSE)
else:
Expand All @@ -37,17 +36,16 @@ def main():
try:
argumentTwo = sys.argv[2]
except IndexError:
exit("No second argument given."
" Try again with a file path as an argument")
exit("No second argument given." " Try again with a file path as an argument")

# Make absolute path if given path is a relative path
if(not os.path.isabs(argumentTwo)):
if not os.path.isabs(argumentTwo):
argumentTwo = os.path.abspath(argumentTwo)

openedContent = ""

# Check if argumentTwo is a valid path and file
if(os.path.exists(argumentTwo) and os.path.isfile(argumentTwo)):
if os.path.exists(argumentTwo) and os.path.isfile(argumentTwo):
# Try to open and read file
try:
openedFile = open(argumentTwo, "r")
Expand All @@ -60,17 +58,17 @@ def main():
matches = []
# Find all phone numbers and store them in matches
for groups in regexCompile.findall(openedContent):
phoneNumber = ''.join(groups)
phoneNumber = "".join(groups)
matches.append(phoneNumber)

openedFile.close()

if len(matches) > 0:
pyperclip.copy(' -+- '.join(matches))
pyperclip.copy(" -+- ".join(matches))
print("Phone number(s) found:")
print('\n'.join(matches))
print("\n".join(matches))
else:
print('No phone numbers or email addresses found.')
print("No phone numbers or email addresses found.")


if __name__ == "__main__":
Expand Down
5 changes: 3 additions & 2 deletions urls/url.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
# protocol (http,https,ftp), www, url with dot something
regexp = re.compile(r'''(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-&?=%.]+''')

# protocol (http,https,ftp), www, url with dot something
regexp = re.compile(r"""(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-&?=%.]+""")
6 changes: 3 additions & 3 deletions urls/urlInClipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def main():
matches.append(url_match)

if len(matches) > 0:
pyperclip.copy(' -+- '.join(matches))
pyperclip.copy(" -+- ".join(matches))
print("Url(s) found:")
print('\n'.join(matches))
print("\n".join(matches))
else:
print('No Url found.')
print("No Url found.")


if __name__ == "__main__":
Expand Down
13 changes: 6 additions & 7 deletions urls/urlInFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ def main():
try:
argumentOne = sys.argv[1]
except IndexError:
exit("No second argument given. "
"Try again with a file path as an argument")
exit("No second argument given. " "Try again with a file path as an argument")

# Make absolute path if given path is a relative path
if(not os.path.isabs(argumentOne)):
if not os.path.isabs(argumentOne):
argumentOne = os.path.abspath(argumentOne)

openedContent = ""

# Check if argumentOne is a valid path and file
if(os.path.exists(argumentOne) and os.path.isfile(argumentOne)):
if os.path.exists(argumentOne) and os.path.isfile(argumentOne):
# Try to open and read file
try:
openedFile = open(argumentOne, "r")
Expand All @@ -42,11 +41,11 @@ def main():
openedFile.close()

if len(matches) > 0:
pyperclip.copy(' -+- '.join(matches))
pyperclip.copy(" -+- ".join(matches))
print("Url(s) found:")
print('\n'.join(matches))
print("\n".join(matches))
else:
print('No Url found.')
print("No Url found.")


if __name__ == "__main__":
Expand Down

0 comments on commit 7bc71ee

Please sign in to comment.