Skip to content

Commit

Permalink
Merge with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian S. Pringle committed Oct 1, 2020
1 parent 6fd8db0 commit c6575d1
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -139,3 +140,7 @@ dmypy.json
.pytype/

# End of https://www.toptal.com/developers/gitignore/api/python
=======
#Ignore enviroment files
/env
>>>>>>> 3c73d451606203216ef00f7bfb7a176bce5a8c43
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- [German](README_de.md)
- [Hindi](README_hi.md)
- [Indonesia](README_idn.md)
13 changes: 12 additions & 1 deletion README_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- [English](README.md)
- [Hindi](README_hi.md)
- [Indonesia](README_idn.md)
25 changes: 25 additions & 0 deletions README_hi.md
Original file line number Diff line number Diff line change
@@ -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)

14 changes: 14 additions & 0 deletions README_idn.md
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions alliterations/alliterationInFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand Down Expand Up @@ -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
31 changes: 31 additions & 0 deletions emailAdresses/emailInFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand Down Expand Up @@ -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
52 changes: 52 additions & 0 deletions phoneNumbers/numberInClipboard.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
#! /usr/bin/env python3
"""
numberInClipboard.py - Finds phone numbers on the
Expand Down Expand Up @@ -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
47 changes: 47 additions & 0 deletions phoneNumbers/numberInFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
>>> numberInFile.py germany C:\\Users\\ExampleUser\\Documents\\phoneNumbers.txt
"""

<<<<<<< HEAD
from countries import countryDict
import pyperclip
import re
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<<<<<<< HEAD
pyperclip == 1.8.0
=======
pyperclip==1.8.0
>>>>>>> 3c73d451606203216ef00f7bfb7a176bce5a8c43

0 comments on commit c6575d1

Please sign in to comment.