import io
import os
import re

#*****************************************************
#               Google Vision API
#*****************************************************

# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types
from google.oauth2 import service_account
credentials = service_account.Credentials. from_service_account_file('key.json')
client = vision.ImageAnnotatorClient(credentials=credentials)    # [END vision_python_migration_client]

for i in range(1,10):
# The name of the image file to annotate (Change the line below 'image_path.jpg' ******)
    file_name = os.path.join(
        os.path.dirname(__file__),
        str(i)+'.jpg') # Your image path from current directory

    with io.open(file_name, 'rb') as image_file:
        content = image_file.read()

    image = vision.types.Image(content=content)

    response = client.text_detection(image=image)
    texts = response.text_annotations

    for text in texts:

        with open('file'+str(i)+'.txt', 'a') as f:
                print('\n"{}"'.format(text.description), file=f)



for j in range(1,10):
    with open('file'+str(j)+'.txt') as in_file:
        for linenum, line in enumerate(in_file):
            if not re.search(r'".*"', line):
                #in_file.write(line)
                print(line)
                with open('file_new'+str(j)+'.txt', "a") as f1:
                    f1.writelines(line)




#*****************************************************
#               Regex
#*****************************************************

#*****************************************************
#               Match MAWB
#*****************************************************


for i in range(1, 10):
    pattern_occur = []                         # The list where we will store results.
    pattern = re.compile(r"(\+\d{3})?[\s.-]?\d{3}[\s.-]?\d{4}[\s.-]?\d{4}")  # Compile a case-insensitive regex pattern.
    try:                              # Try to:
        with open ('file_new'+str(i)+'.txt', 'rt') as in_file:        # open file for reading text.

            for linenum, line in enumerate(in_file):        # Keep track of line numbers.
                if pattern.search(line) != None:          # If substring search finds a match,
                    pattern_occur.append((linenum, line.rstrip('\n'))) # strip linebreaks, store line and line number in list as tuple.
            for linenum, line in pattern_occur:              # Iterate over the list of tuples, and
                a=line
            print('MAWB : '+a+'\n')   # prints MAWB number of every  file

    except FileNotFoundError:                   # If log file not found.

        print("Log file not found.")                # print an error message.

# *****************************************************
#               Match Consignee
# *****************************************************

    linesCo = [] #Declare an empty list named "lines"
    with open ('file_new'+str(i)+'.txt', 'rt') as in_file:  #Open file fire4.txt for reading of text data.

        for line in in_file: #For each line of text store in a string variable named "line", and
            index = 0  # index represents where in the string we begin looking.

            linesCo.append(line.rstrip('\n'))  #add that line to our list of lines.
            #str = linesCo[0]
            substr = "Consigne"         # Substring to search for, in this case a single character
            substr2 = "CONSIGNE"

            #print(str)

        for linenum, line in enumerate(linesCo):  # For every line in lines, enumerated by linenum,
            index = 0
            index2 = 0  # Set the search index to the first character,
            str2 = linesCo[linenum]	    # and store the line in a string variable, str.
            #print(line)

            while index < len(str2):     # While search index is less than the length of the string:
                index = str2.find(substr, index)# If substring is located, set search index to that location.
                if index == -1:         # If nothing is found,
                    #print('index = -1')
                    break               # break out of the while loop. Otherwise

                print(str2) # Print the linenum and index of the located substr.
                li = linesCo[linenum:linenum + 5]

                index += len(substr)    # Before repeating search, increment index by length of substr." " "
                a=li
                print(a)

            while index2 < len(str2):     # While search index is less than the length of the string:
                index2 = str2.find(substr2, index2)# If substring is located, set search index to that location.
                if index2 == -1:         # If nothing is found,
                    #print('index = -1')
                    break               # break out of the while loop. Otherwise

                print(str2) # Print the linenum and index of the located substr.
                li2 = linesCo[linenum:linenum + 5]

                index2 += len(substr2)    # Before repeating search, increment index by length of substr." " "
                b=li2
                print(b)


# *****************************************************
#               Match Port of Destination
# *****************************************************


        with open('file_new'+str(i)+'.txt', 'rt') as in_file:  # Open file fire4.txt for reading of text data.
            searchstrings = ('DEL', 'MAA', 'BLR', 'BOM', 'HYD', 'CCU')
            for line in in_file:
                if any(word in line for word in searchstrings):
                    #print(line)
                    c = line


        print(' \n Port of Destination '+ c +'\n\n\n')



4885868916bbc87374f9c9cf63b930d9cc2e5ceb
<mask token>

<mask token>
for i in range(1, 10):
    file_name = os.path.join(os.path.dirname(__file__), str(i) + '.jpg')
    with io.open(file_name, 'rb') as image_file:
        content = image_file.read()
    image = vision.types.Image(content=content)
    response = client.text_detection(image=image)
    texts = response.text_annotations
    for text in texts:
        with open('file' + str(i) + '.txt', 'a') as f:
            print('\n"{}"'.format(text.description), file=f)
for j in range(1, 10):
    with open('file' + str(j) + '.txt') as in_file:
        for linenum, line in enumerate(in_file):
            if not re.search('".*"', line):
                print(line)
                with open('file_new' + str(j) + '.txt', 'a') as f1:
                    f1.writelines(line)
for i in range(1, 10):
    pattern_occur = []
    pattern = re.compile(
        '(\\+\\d{3})?[\\s.-]?\\d{3}[\\s.-]?\\d{4}[\\s.-]?\\d{4}')
    try:
        with open('file_new' + str(i) + '.txt', 'rt') as in_file:
            for linenum, line in enumerate(in_file):
                if pattern.search(line) != None:
                    pattern_occur.append((linenum, line.rstrip('\n')))
            for linenum, line in pattern_occur:
                a = line
            print('MAWB : ' + a + '\n')
    except FileNotFoundError:
        print('Log file not found.')
    linesCo = []
    with open('file_new' + str(i) + '.txt', 'rt') as in_file:
        for line in in_file:
            index = 0
            linesCo.append(line.rstrip('\n'))
            substr = 'Consigne'
            substr2 = 'CONSIGNE'
        for linenum, line in enumerate(linesCo):
            index = 0
            index2 = 0
            str2 = linesCo[linenum]
            while index < len(str2):
                index = str2.find(substr, index)
                if index == -1:
                    break
                print(str2)
                li = linesCo[linenum:linenum + 5]
                index += len(substr)
                a = li
                print(a)
            while index2 < len(str2):
                index2 = str2.find(substr2, index2)
                if index2 == -1:
                    break
                print(str2)
                li2 = linesCo[linenum:linenum + 5]
                index2 += len(substr2)
                b = li2
                print(b)
        with open('file_new' + str(i) + '.txt', 'rt') as in_file:
            searchstrings = 'DEL', 'MAA', 'BLR', 'BOM', 'HYD', 'CCU'
            for line in in_file:
                if any(word in line for word in searchstrings):
                    c = line
        print(' \n Port of Destination ' + c + '\n\n\n')

<mask token>
credentials = service_account.Credentials.from_service_account_file('key.json')
client = vision.ImageAnnotatorClient(credentials=credentials)
for i in range(1, 10):
    file_name = os.path.join(os.path.dirname(__file__), str(i) + '.jpg')
    with io.open(file_name, 'rb') as image_file:
        content = image_file.read()
    image = vision.types.Image(content=content)
    response = client.text_detection(image=image)
    texts = response.text_annotations
    for text in texts:
        with open('file' + str(i) + '.txt', 'a') as f:
            print('\n"{}"'.format(text.description), file=f)
for j in range(1, 10):
    with open('file' + str(j) + '.txt') as in_file:
        for linenum, line in enumerate(in_file):
            if not re.search('".*"', line):
                print(line)
                with open('file_new' + str(j) + '.txt', 'a') as f1:
                    f1.writelines(line)
for i in range(1, 10):
    pattern_occur = []
    pattern = re.compile(
        '(\\+\\d{3})?[\\s.-]?\\d{3}[\\s.-]?\\d{4}[\\s.-]?\\d{4}')
    try:
        with open('file_new' + str(i) + '.txt', 'rt') as in_file:
            for linenum, line in enumerate(in_file):
                if pattern.search(line) != None:
                    pattern_occur.append((linenum, line.rstrip('\n')))
            for linenum, line in pattern_occur:
                a = line
            print('MAWB : ' + a + '\n')
    except FileNotFoundError:
        print('Log file not found.')
    linesCo = []
    with open('file_new' + str(i) + '.txt', 'rt') as in_file:
        for line in in_file:
            index = 0
            linesCo.append(line.rstrip('\n'))
            substr = 'Consigne'
            substr2 = 'CONSIGNE'
        for linenum, line in enumerate(linesCo):
            index = 0
            index2 = 0
            str2 = linesCo[linenum]
            while index < len(str2):
                index = str2.find(substr, index)
                if index == -1:
                    break
                print(str2)
                li = linesCo[linenum:linenum + 5]
                index += len(substr)
                a = li
                print(a)
            while index2 < len(str2):
                index2 = str2.find(substr2, index2)
                if index2 == -1:
                    break
                print(str2)
                li2 = linesCo[linenum:linenum + 5]
                index2 += len(substr2)
                b = li2
                print(b)
        with open('file_new' + str(i) + '.txt', 'rt') as in_file:
            searchstrings = 'DEL', 'MAA', 'BLR', 'BOM', 'HYD', 'CCU'
            for line in in_file:
                if any(word in line for word in searchstrings):
                    c = line
        print(' \n Port of Destination ' + c + '\n\n\n')

import io
import os
import re
from google.cloud import vision
from google.cloud.vision import types
from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_file('key.json')
client = vision.ImageAnnotatorClient(credentials=credentials)
for i in range(1, 10):
    file_name = os.path.join(os.path.dirname(__file__), str(i) + '.jpg')
    with io.open(file_name, 'rb') as image_file:
        content = image_file.read()
    image = vision.types.Image(content=content)
    response = client.text_detection(image=image)
    texts = response.text_annotations
    for text in texts:
        with open('file' + str(i) + '.txt', 'a') as f:
            print('\n"{}"'.format(text.description), file=f)
for j in range(1, 10):
    with open('file' + str(j) + '.txt') as in_file:
        for linenum, line in enumerate(in_file):
            if not re.search('".*"', line):
                print(line)
                with open('file_new' + str(j) + '.txt', 'a') as f1:
                    f1.writelines(line)
for i in range(1, 10):
    pattern_occur = []
    pattern = re.compile(
        '(\\+\\d{3})?[\\s.-]?\\d{3}[\\s.-]?\\d{4}[\\s.-]?\\d{4}')
    try:
        with open('file_new' + str(i) + '.txt', 'rt') as in_file:
            for linenum, line in enumerate(in_file):
                if pattern.search(line) != None:
                    pattern_occur.append((linenum, line.rstrip('\n')))
            for linenum, line in pattern_occur:
                a = line
            print('MAWB : ' + a + '\n')
    except FileNotFoundError:
        print('Log file not found.')
    linesCo = []
    with open('file_new' + str(i) + '.txt', 'rt') as in_file:
        for line in in_file:
            index = 0
            linesCo.append(line.rstrip('\n'))
            substr = 'Consigne'
            substr2 = 'CONSIGNE'
        for linenum, line in enumerate(linesCo):
            index = 0
            index2 = 0
            str2 = linesCo[linenum]
            while index < len(str2):
                index = str2.find(substr, index)
                if index == -1:
                    break
                print(str2)
                li = linesCo[linenum:linenum + 5]
                index += len(substr)
                a = li
                print(a)
            while index2 < len(str2):
                index2 = str2.find(substr2, index2)
                if index2 == -1:
                    break
                print(str2)
                li2 = linesCo[linenum:linenum + 5]
                index2 += len(substr2)
                b = li2
                print(b)
        with open('file_new' + str(i) + '.txt', 'rt') as in_file:
            searchstrings = 'DEL', 'MAA', 'BLR', 'BOM', 'HYD', 'CCU'
            for line in in_file:
                if any(word in line for word in searchstrings):
                    c = line
        print(' \n Port of Destination ' + c + '\n\n\n')

import io
import os
import re

#*****************************************************
#               Google Vision API
#*****************************************************

# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types
from google.oauth2 import service_account
credentials = service_account.Credentials. from_service_account_file('key.json')
client = vision.ImageAnnotatorClient(credentials=credentials)    # [END vision_python_migration_client]

for i in range(1,10):
# The name of the image file to annotate (Change the line below 'image_path.jpg' ******)
    file_name = os.path.join(
        os.path.dirname(__file__),
        str(i)+'.jpg') # Your image path from current directory

    with io.open(file_name, 'rb') as image_file:
        content = image_file.read()

    image = vision.types.Image(content=content)

    response = client.text_detection(image=image)
    texts = response.text_annotations

    for text in texts:

        with open('file'+str(i)+'.txt', 'a') as f:
                print('\n"{}"'.format(text.description), file=f)



for j in range(1,10):
    with open('file'+str(j)+'.txt') as in_file:
        for linenum, line in enumerate(in_file):
            if not re.search(r'".*"', line):
                #in_file.write(line)
                print(line)
                with open('file_new'+str(j)+'.txt', "a") as f1:
                    f1.writelines(line)




#*****************************************************
#               Regex
#*****************************************************

#*****************************************************
#               Match MAWB
#*****************************************************


for i in range(1, 10):
    pattern_occur = []                         # The list where we will store results.
    pattern = re.compile(r"(\+\d{3})?[\s.-]?\d{3}[\s.-]?\d{4}[\s.-]?\d{4}")  # Compile a case-insensitive regex pattern.
    try:                              # Try to:
        with open ('file_new'+str(i)+'.txt', 'rt') as in_file:        # open file for reading text.

            for linenum, line in enumerate(in_file):        # Keep track of line numbers.
                if pattern.search(line) != None:          # If substring search finds a match,
                    pattern_occur.append((linenum, line.rstrip('\n'))) # strip linebreaks, store line and line number in list as tuple.
            for linenum, line in pattern_occur:              # Iterate over the list of tuples, and
                a=line
            print('MAWB : '+a+'\n')   # prints MAWB number of every  file

    except FileNotFoundError:                   # If log file not found.

        print("Log file not found.")                # print an error message.

# *****************************************************
#               Match Consignee
# *****************************************************

    linesCo = [] #Declare an empty list named "lines"
    with open ('file_new'+str(i)+'.txt', 'rt') as in_file:  #Open file fire4.txt for reading of text data.

        for line in in_file: #For each line of text store in a string variable named "line", and
            index = 0  # index represents where in the string we begin looking.

            linesCo.append(line.rstrip('\n'))  #add that line to our list of lines.
            #str = linesCo[0]
            substr = "Consigne"         # Substring to search for, in this case a single character
            substr2 = "CONSIGNE"

            #print(str)

        for linenum, line in enumerate(linesCo):  # For every line in lines, enumerated by linenum,
            index = 0
            index2 = 0  # Set the search index to the first character,
            str2 = linesCo[linenum]	    # and store the line in a string variable, str.
            #print(line)

            while index < len(str2):     # While search index is less than the length of the string:
                index = str2.find(substr, index)# If substring is located, set search index to that location.
                if index == -1:         # If nothing is found,
                    #print('index = -1')
                    break               # break out of the while loop. Otherwise

                print(str2) # Print the linenum and index of the located substr.
                li = linesCo[linenum:linenum + 5]

                index += len(substr)    # Before repeating search, increment index by length of substr." " "
                a=li
                print(a)

            while index2 < len(str2):     # While search index is less than the length of the string:
                index2 = str2.find(substr2, index2)# If substring is located, set search index to that location.
                if index2 == -1:         # If nothing is found,
                    #print('index = -1')
                    break               # break out of the while loop. Otherwise

                print(str2) # Print the linenum and index of the located substr.
                li2 = linesCo[linenum:linenum + 5]

                index2 += len(substr2)    # Before repeating search, increment index by length of substr." " "
                b=li2
                print(b)


# *****************************************************
#               Match Port of Destination
# *****************************************************


        with open('file_new'+str(i)+'.txt', 'rt') as in_file:  # Open file fire4.txt for reading of text data.
            searchstrings = ('DEL', 'MAA', 'BLR', 'BOM', 'HYD', 'CCU')
            for line in in_file:
                if any(word in line for word in searchstrings):
                    #print(line)
                    c = line


        print(' \n Port of Destination '+ c +'\n\n\n')


