From c6575d18b26d1845d43bf57ba34581b59f04aa15 Mon Sep 17 00:00:00 2001 From: "Ian S. Pringle" Date: Thu, 1 Oct 2020 09:00:38 -0400 Subject: [PATCH] Merge with upstream --- .gitignore | 5 +++ README.md | 13 +++++++- README_de.md | 13 +++++++- README_hi.md | 25 ++++++++++++++ README_idn.md | 14 ++++++++ alliterations/alliterationInFile.py | 26 +++++++++++++++ emailAdresses/emailInFile.py | 31 +++++++++++++++++ phoneNumbers/numberInClipboard.py | 52 +++++++++++++++++++++++++++++ phoneNumbers/numberInFile.py | 47 ++++++++++++++++++++++++++ requirements.txt | 4 +++ 10 files changed, 228 insertions(+), 2 deletions(-) create mode 100644 README_hi.md create mode 100644 README_idn.md diff --git a/.gitignore b/.gitignore index 2729cb2..66416c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +<<<<<<< HEAD # Created by https://www.toptal.com/developers/gitignore/api/python # Edit at https://www.toptal.com/developers/gitignore?templates=python @@ -139,3 +140,7 @@ dmypy.json .pytype/ # End of https://www.toptal.com/developers/gitignore/api/python +======= +#Ignore enviroment files +/env +>>>>>>> 3c73d451606203216ef00f7bfb7a176bce5a8c43 diff --git a/README.md b/README.md index c3111e5..e538edb 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,16 @@ Feel free to contribute but please keep things easy to understand. - sys (command line arguments) - os (functions for filepathes) +## How to contribute: +1. Fork this repository +2. Clone the forked repository +3. Write your code +4. Create a new branch +5. Open a pull request + +See [this tutorial](https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github) for more information. + ## READMEs in other languages: -- [German](README_de.md) \ No newline at end of file +- [German](README_de.md) +- [Hindi](README_hi.md) +- [Indonesia](README_idn.md) diff --git a/README_de.md b/README_de.md index 061a247..5f1fa69 100644 --- a/README_de.md +++ b/README_de.md @@ -8,5 +8,16 @@ Du kannst gerne etwas beitragen, aber bitte halte die Dinge leicht und verständ - sys (Kommandozeilenargumente) - os (Funktionen für die Dateipfade) +## So trägst du etwas bei: +1. Dieses Repository forken +2. Klonen des geforkten Repositories +3. Neuen Code hinzufügen +4. Neuen Branch erstellen +5. Pull-Request eröffnen + +[Dieses Tutorial](https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github) beinhaltet noch weiterführende Informationen. + ## READMEs in anderen Sprachen: -- [English](README.md) \ No newline at end of file +- [English](README.md) +- [Hindi](README_hi.md) +- [Indonesia](README_idn.md) diff --git a/README_hi.md b/README_hi.md new file mode 100644 index 0000000..e0622de --- /dev/null +++ b/README_hi.md @@ -0,0 +1,25 @@ +# पाइथन के साथ खोजें (FindingThingsWithPython) +पाइथन के साथ ग्रंथो/टेक्स्ट में चीजों को खोजने के लिए छोटी और आसान स्क्रिप्ट्स | +योगदान करने के लिए स्वतंत्र महसूस करें लेकिन कृपया चीजों को समझने में आसान रखें। + +## आयात (और उपयोग)[Imports (and use)] : +इन्हें पाइथन में आयात करें +- pyperclip (क्लिपबोर्ड पर / से सामग्री कॉपी और पेस्ट करे) +- re (regular expressions) +- sys (command line arguments) +- os (फाइल paths के लिए functions) + +## योगदान कैसे करें: +1. इस Repository को Fork कीजिये +2. Fork की हुई repository को clone करें +3. Code लिखें +4. नयी branch बनाएं +5. Pull request करें + +अधिक जानकारी के लिए [इस ट्यूटोरियल](https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github) को देखें | + +## अन्य भाषाओँ में READMEs : +- [English](README.md) +- [German](README_de.md) +- [Indonesia](README_idn.md) + diff --git a/README_idn.md b/README_idn.md new file mode 100644 index 0000000..bb82078 --- /dev/null +++ b/README_idn.md @@ -0,0 +1,14 @@ +# FindingThingsWithPython +Skrip singkat dan mudah untuk menemukan teks dengan bahasa pemrograman python. +Silahkan untuk berkonrtibusi. Harap tetap menjaga agar dapat tetap mudah dimengerti/ dipahami. + +## Imports (dan penggunaan): +- pyperclip (copy (salin) dan paste (tempel) konten dari/ke clipboard) +- re (ekspresi regular) +- sys (argumen command line) +- os (fungsi untuk filepathes (alur file)) + +## READMEs in other languages: +- [English](README.md) +- [German](README_de.md) +- [Hindi](README_hi.md) \ No newline at end of file diff --git a/alliterations/alliterationInFile.py b/alliterations/alliterationInFile.py index 8db5b7f..4a549d5 100644 --- a/alliterations/alliterationInFile.py +++ b/alliterations/alliterationInFile.py @@ -13,6 +13,7 @@ def main(): # Check if sys.argv[1] is given argumentOne = "" try: +<<<<<<< HEAD argumentOne = sys.argv[1] except IndexError: exit("No second argument given. " @@ -52,3 +53,28 @@ def main(): if __name__ == "__main__": main() +======= + openedFile = open(argumentOne, "r",encoding='ascii',errors='ignore') + openedContent = openedFile.read() + except OSError: + exit("Could not open file") +else: + exit("Given file does not exist: " + argumentOne) + +# Create alliteration regex. +alliRegex = re.compile(r"((\s)(\w)\w*\s\3\w*((\s\3\w*)?)*)", re.IGNORECASE) + +matches = [] +for groups in alliRegex.findall(openedContent): + alliterations = groups[0][1:] + matches.append(alliterations) + +openedFile.close() + +if len(matches) > 0: + pyperclip.copy(' -+- '.join(matches)) + print("Alliteration(s) found:") + print('\n'.join(matches)) +else: + print('No alliteration found.') +>>>>>>> 3c73d451606203216ef00f7bfb7a176bce5a8c43 diff --git a/emailAdresses/emailInFile.py b/emailAdresses/emailInFile.py index 6eebd25..c5f49b3 100644 --- a/emailAdresses/emailInFile.py +++ b/emailAdresses/emailInFile.py @@ -13,6 +13,7 @@ def main(): # Check if sys.argv[1] is given argumentOne = "" try: +<<<<<<< HEAD argumentOne = sys.argv[1] except IndexError: exit("No second argument given. " @@ -52,3 +53,33 @@ def main(): if __name__ == "__main__": main() +======= + openedFile = open(argumentOne, "r",encoding='ascii',errors='ignore') + openedContent = openedFile.read() + except OSError: + exit("Could not open file") +else: + exit("Given file does not exist: " + argumentOne) + +# Create email regex. +emailRegex = re.compile(r'''( + [a-zA-Z0-9._%+-]+ # username + @ # @ symbol + [a-zA-Z0-9.-]+ # domain name + (\.[a-zA-Z]{2,4}) # dot-something + )''', re.VERBOSE) + +matches = [] +for groups in emailRegex.findall(openedContent): + emails = groups[0] + matches.append(emails) + +openedFile.close() + +if len(matches) > 0: + pyperclip.copy(' -+- '.join(matches)) + print("Email address(es) found:") + print('\n'.join(matches)) +else: + print('No email address found.') +>>>>>>> 3c73d451606203216ef00f7bfb7a176bce5a8c43 diff --git a/phoneNumbers/numberInClipboard.py b/phoneNumbers/numberInClipboard.py index 263b7fe..2af52e8 100644 --- a/phoneNumbers/numberInClipboard.py +++ b/phoneNumbers/numberInClipboard.py @@ -1,3 +1,4 @@ +<<<<<<< HEAD #! /usr/bin/env python3 """ numberInClipboard.py - Finds phone numbers on the @@ -45,3 +46,54 @@ def main(): if __name__ == "__main__": main() +======= +#! python3 +# numberInClipboard.py - Finds phone numbers on the clipboard and copies them to the clipboard +# Usage: Copy some text and call the program with a country as the first argument +# Example: >>> numberOnClipboard.py germany + +import pyperclip, re, sys + +#Create dictionary to store regex expressions for different countries +countryDict = {} + +#Create phone regex for country specific number format and add it to countryDict + +germany = r'''( + (\d{3}|\(\d{3}\))? # area code (optional) + (\s|-|\.|/)? # separator (optional) + (\d{7,9}) # 7 to 9 digits + )''' +spain = r"(^[98](\d{8}))" +countryDict["germany"] = germany +countryDict["spain"] = spain + +# Check if sys.argv[1] in countryDict and create regex object +argumentOne = "" +try: + argumentOne = sys.argv[1] +except IndexError: + exit("No argument given. Try again with a country as an argument") + +if(argumentOne in countryDict): + #Create regex object + regexCompile = re.compile(countryDict[argumentOne], re.VERBOSE|re.MULTILINE) +else: + exit("No number format for that country found") + + + +# Find matches in clipboard text. +text = str(pyperclip.paste()) +matches = [] +for groups in regexCompile.findall(text): + phoneNumber = groups[0] + matches.append(phoneNumber) + +if len(matches) > 0: + pyperclip.copy(' -+- '.join(matches)) + print("Phone number(s) found:") + print('\n'.join(matches)) +else: + print('No phone number found.') +>>>>>>> 3c73d451606203216ef00f7bfb7a176bce5a8c43 diff --git a/phoneNumbers/numberInFile.py b/phoneNumbers/numberInFile.py index 0c9a903..682c9a0 100644 --- a/phoneNumbers/numberInFile.py +++ b/phoneNumbers/numberInFile.py @@ -10,6 +10,7 @@ >>> numberInFile.py germany C:\\Users\\ExampleUser\\Documents\\phoneNumbers.txt """ +<<<<<<< HEAD from countries import countryDict import pyperclip import re @@ -25,6 +26,30 @@ def main(): except IndexError: exit("No argument given." " Try again with a country as an argument") +======= +#Create phone regex for country specific number format and add it to countryDict +germany = r'''( + (\d{3}|\(\d{3}\))? # area code (optional) + (\s|-|\.|/)? # separator (optional) + (\d{7,9}) # 7 to 9 digits + )''' +spain = r"(^[98](\d{8}))" + +countryDict["germany"] = germany +countryDict["spain"] = spain +# Check if sys.argv[1] is given and in countryDict +argumentOne = "" +try: + argumentOne = sys.argv[1] +except IndexError: + exit("No argument given. Try again with a country as an argument") + +if(argumentOne in countryDict): + #Create regex object + regexCompile = re.compile(countryDict[argumentOne], re.VERBOSE|re.MULTILINE) +else: + exit("No number format for that country found") +>>>>>>> 3c73d451606203216ef00f7bfb7a176bce5a8c43 if(argumentOne in countryDict): # Create regex object @@ -46,6 +71,7 @@ def main(): openedContent = "" +<<<<<<< HEAD # Check if argumentTwo is a valid path and file if(os.path.exists(argumentTwo) and os.path.isfile(argumentTwo)): # Try to open and read file @@ -64,6 +90,18 @@ def main(): matches.append(phoneNumber) openedFile.close() +======= +# Check if argumentTwo is a valid path and file +if(os.path.exists(argumentTwo) and os.path.isfile(argumentTwo)): + # Try to open and read file + try: + openedFile = open(argumentTwo, "r",encoding='ascii',errors='ignore') + openedContent = openedFile.read() + except OSError: + exit("Could not open file") +else: + exit("Given file does not exist: " + argumentTwo) +>>>>>>> 3c73d451606203216ef00f7bfb7a176bce5a8c43 if len(matches) > 0: pyperclip.copy(' -+- '.join(matches)) @@ -73,5 +111,14 @@ def main(): print('No phone numbers or email addresses found.') +<<<<<<< HEAD if __name__ == "__main__": main() +======= +if len(matches) > 0: + pyperclip.copy(' -+- '.join(matches)) + print("Phone number(s) found:") + print('\n'.join(matches)) +else: + print('No phone numbers or email addresses found.') +>>>>>>> 3c73d451606203216ef00f7bfb7a176bce5a8c43 diff --git a/requirements.txt b/requirements.txt index 31df57d..e94f72b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,5 @@ +<<<<<<< HEAD pyperclip == 1.8.0 +======= +pyperclip==1.8.0 +>>>>>>> 3c73d451606203216ef00f7bfb7a176bce5a8c43