Beispiel #1
0
def main():
    
    with open('last.log', 'r') as fd:
        global EVENTS
        EVENTS = parse(fd)
        
    
    g = Graph(EVENTS)
    g.make_graph()
    
#    make_graph()
#
##    with open('my.dot', 'wb') as fd:
##        make_mydot(fd)
#        
    with closing(StringIO()) as fd:
        g.make_dot(fd)
        with open('test.dot', 'wb') as ffd:
            ffd.write(fd.getvalue())
        win = xdot.DotWindow()
        win.set_dotcode(fd.getvalue())
        win.connect('destroy', gtk.main_quit)
        gtk.main()

    pass
    def parse_one_person():
        file = io.StringIO("1;Nicolette Champlin")
        res = file_parser.parse(file)
        person = res[0]

        assert_that(person.name, equal_to("Nicolette Champlin"))
        assert_that(person.id, equal_to("1"))
    def parse_one_person():
        file = io.StringIO("1;Nicolette Champlin")
        res = file_parser.parse(file)
        person = res[0]

        assert_that(person.name, equal_to("Nicolette Champlin"))
        assert_that(person.id, equal_to("1"))
    def returns_one_user():
        res = io.StringIO('''1;Jens Gustafsson
2; Henrik Gudmunssson''')
        persons = file_parser.parse(res)
        assert_that(persons, has_length(2))
        assert_that(persons[0].id, equal_to("1"))
        assert_that(persons[0].name, equal_to("Jens Gustafsson"))
    def returns_person_with_appointment():
        res = io.StringIO('''1;3/13/2015 8:00:00 AM;3/13/2015 1:00:00 PM;C5CA
1;Jens Gustafsson''')
        person_with_appointment = file_parser.parse(res)
        assert_that(person_with_appointment, has_length(1))
        person = person_with_appointment[0]
        assert_that(person, instance_of(file_parser.Person))
        assert_that(person.appointments, has_length(1))
Beispiel #6
0
def HandleNewEmail(mail_path):
    #Parse email to store in DB
    #print(type(mail_path))
    #added this for image remove if problematic
    if (mail_path.endswith('.png') or mail_path.endswith('.jpg') or mail_path.endswith('.jpeg')):
        #print('Email Image uploaded!!')
        extracted_text = ocr(mail_path)
        email = extracted_text.split('\n')

    if (mail_path.endswith('.pdf')):
        #print('PDF received')
        extracted_text = parse(mail_path)
        email = extracted_text.split('\n')
        #print(email)

    if (mail_path.endswith('.txt')):
        #print('txt received')
        email=open(mail_path, "r")

    to_add=''
    from_add=''
    sub=''
    body=''
    for line in email:
            #print(f'**{line}**')
            if line.startswith('To: ') or line.startswith('to: '):
                pieces = line.split()
                to_add = pieces[1]
                #print(f'To---->Found!!!{to_add}')
                continue
            if line.startswith('From: ') or line.startswith('from: '):
                pieces=line.split()
                from_add=pieces[1]
                continue
            if line.startswith('Subject: ') or line.startswith('subject: '):
                pieces=line.split()
                subject=pieces[1:]#remove word subject
                for word in subject:
                    sub = sub + " " + word
               # text=text+" "
                continue
            body=body + line
    text=sub + " " + body
    receivedDate = time.ctime(os.path.getctime(mail_path))

    if (mail_path.endswith('.txt')):
        email.close()
        #print(encoded_mail)

    outputclass , id = inp(to_add,from_add,sub,body)

    #addtoDB(to_add, from_add, receivedDate, sub, id, body, outputclass)
    moveEmail(mail_path, outputclass)
    print(f'====>Event Processing completed')

    return to_add, from_add, receivedDate, sub, id, body, outputclass
    def parse_person_with_appointment():
        file = io.StringIO('''1;Nicolette Champlin
1;1/8/2015 11:30:00 AM;1/8/2015 2:00:00 PM;ABC''')

        res = file_parser.parse(file)
        person = res[0]

        assert_that(person.id, equal_to("1"))
        assert_that(person.name, equal_to("Nicolette Champlin"))
        assert_that(person.appointments, has_length(1))
    def parse_person_with_appointment():
        file = io.StringIO('''1;Nicolette Champlin
1;1/8/2015 11:30:00 AM;1/8/2015 2:00:00 PM;ABC''')

        res = file_parser.parse(file)
        person = res[0]

        assert_that(person.id, equal_to("1"))
        assert_that(person.name, equal_to("Nicolette Champlin"))
        assert_that(person.appointments, has_length(1))
def generate(dna_path, header, filename, output_path, loading_bar):
    """
    Pulls together numerous functions to generate the pdf report

    :param dna_path:
    Path to the DNA file

    :param header:
    Paragraph at the top of the document

    :param filename:
    Name of the file to be created

    :param output_path:
    Destination for the report

    :return:
    The path to the generated report
    """

    # Get the predefined groups
    groups = group_mngr.load_groups()

    loading_bar.value = 10

    # Create variable to hold the active service, assigned below
    service = _detect_service(dna_path)  # Returns "AncestryDNA" or "23&Me"

    loading_bar.value = 20

    # Get the genes from the provided file
    pulled_genes = file_parser.parse(groups, dna_path, service)

    loading_bar.value += 50

    # Create the pdf with given info
    write_report(groups,
                 pulled_genes,
                 filename,
                 output_path,
                 service,
                 header=header)

    loading_bar.value = 75

    # Return the path the file was saved to
    file_path = output_path + f"/{filename}.pdf"

    return file_path
 def returns_one_user():
     res = io.StringIO("1;Jens Gustafsson")
     persons = file_parser.parse(res)
     assert_that(persons, has_length(1))
     assert_that(persons[0].id, equal_to("1"))
     assert_that(persons[0].name, equal_to("Jens Gustafsson"))
 def returns_empty_result_when_file_is_empty():
     res = io.StringIO("")
     persons = file_parser.parse(res)
     assert_that(persons, has_length(0))
Beispiel #12
0
import file_parser as file_parser
import requests
from bs4 import BeautifulSoup
import json
import goslate
from langdetect import detect

sites, label = file_parser.parse("dataset.txt")
gs = goslate.Goslate()
i = 0
x_training = []
x_test = []
y_training = []
y_test = []
with open("lang_file.json", encoding="utf8") as json_file:
    data = json.load(json_file)

print(data["it"])
j = 0
print("==================== Download Pages =====================")
e_commerce = []
for site in sites:
    try:
        i = i + 1
        if "amazon" in site:
            headers = {
                'User-Agent':
                'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36'
            }
            page = requests.get(site, headers=headers)
            soup = BeautifulSoup(page.content, 'lxml')
 def returns_empty_list_if_file_is_empty():
     empty_file = io.StringIO("")
     res = file_parser.parse(empty_file)
     assert_that(res, empty())
Beispiel #14
0
def parse(d):
    return file_parser.parse(d)
 def returns_a_user_without_name_and_one_meeting():
     res = io.StringIO("1;3/13/2015 8:00:00 AM;3/13/2015 1:00:00 PM;C5CA")
     persons = file_parser.parse(res)
     assert_that(persons[0].name, equal_to(""))
     assert_that(persons[0].appointments[0].start, equal_to(file_parser.parse_date("3/13/2015 8:00:00 AM")))
Beispiel #16
0

def convert_rules_list_to_dict(rules):
  rules_dict = {}
  for rule in rules:
    rules_dict[rule.head] = rule
  return rules_dict


if __name__ == "__main__":
  rules_files = ['Sample4.in']
  input_string_file_template = 'input{0}.in'
  output_parse_tree_file_template = 'my-ouput{0}.out'
  parse_trees = []
  for file in rules_files:
    variables, terminals, rules = file_parser.parse(file)
    rules_dict = convert_rules_list_to_dict(rules)
    first_sets = first.get(variables, rules_dict)
    follow_sets = follow.get(variables, rules, first_sets)
    # change terminals to include $ instead of !
    terminals[-1] = '$'
    parsing_table = table_builder.build(variables, terminals, first_sets, follow_sets, rules_dict)
    print('Rules: ')
    print('\n'.join(map(str, rules)))
    print('              ---------------')
    print('First Sets: ')
    print(first_sets)
    print('              ---------------')
    print('Follow Sets: ')
    print(follow_sets)
    print('              ---------------')
Beispiel #17
0
def handle_new_email(mail_path):
    """
    Extract text from email depending on file type
    Call model to get output class
    Return to_add, from_add, received_date, sub, tid, body, outputclass
    """
    #print(type(mail_path))
    #added this for image remove if problematic
    if (mail_path.endswith('.png') or mail_path.endswith('.jpg') or
            mail_path.endswith('.jpeg')):
        #print('Email Image uploaded!!')
        extracted_text = ocr(mail_path)
        email = extracted_text.split('\n')

    elif mail_path.endswith('.pdf'):
        #print('PDF received')
        extracted_text = parse(mail_path)
        email = extracted_text.split('\n')
        #print(email)

    elif mail_path.endswith('.txt'):
        #print('txt received')
        email = open(mail_path, "r")
    else:
        #Unhandled file type
        return '', '', '', '', '', '', ''

    to_add = ''
    from_add = ''
    sub = ''
    body = ''
    for line in email:
        #print(f'**{line}**')
        if line.startswith('To: ') or line.startswith('to: '):
            pieces = line.split()
            to_add = pieces[1]
            #print(f'To---->Found!!!{to_add}')
            continue
        if line.startswith('From: ') or line.startswith('from: '):
            pieces = line.split()
            from_add = pieces[1]
            continue
        if line.startswith('Subject: ') or line.startswith('subject: '):
            pieces = line.split()
            subject = pieces[1:]#remove word subject
            for word in subject:
                sub = sub + " " + word
            # text=text+" "
            continue
        body = body + line
    #text = sub + " " + body
    received_date = time.ctime(os.path.getctime(mail_path))

    if mail_path.endswith('.txt'):
        email.close()
        #print(encoded_mail)

    outputclass, tid, amt = inp(to_add, from_add, sub, body)

    #add_to_db(to_add, from_add, received_date, sub, tid, body, outputclass)
    #move_email(mail_path, outputclass)
    print(f'====>Event Processing completed')

    return to_add, from_add, received_date, sub, tid, body, outputclass
from file_parser import parse
from rank_counter import count
from page_downloader import download
'''
Scrape https://moongourd.com/ "Class Rankings" stats for Solo Heal for your desired dungeon & boss
Outputs the number of times a class has been found
'''

if __name__ == '__main__':
    # your desired url here
    url = "https://moongourd.com/eu/hiscores?area=3126&boss=1000&class=All%20Classes"
    # the number of ranks to take into account
    target_ranks = 100
    download(url)
    filename = "input.html"
    rank = {
        "Valkyrie": 0,
        "Warrior": 0,
        "Berserker": 0,
        "Slayer": 0,
        "Ninja": 0,
        "Sorcerer": 0,
        "Gunner": 0,
        "Archer": 0,
        "Reaper": 0
    }
    parsed_file = parse(filename, target_ranks)
    result = count(rank, parsed_file)
    for i in result:
        print(f"Class: {i}, Appeared {rank[i]} times")
 def returns_empty_list_if_file_is_empty():
     empty_file = io.StringIO("")
     res = file_parser.parse(empty_file)
     assert_that(res, empty())
Beispiel #20
0
    for item in only_shopping_list_updated:
        all_possible_sorted_combinations.append(sorted(list(set(itertools.combinations(item, step)))))
    return all_possible_sorted_combinations


def get_candidate_list_allowed(flatten_list, allow_level, mode=0):
    if mode == 1:
        res = Counter(flatten_list)
    else:
        res = Counter(map(tuple, flatten_list))
    return [key for key, value in res.items() if value >= allow_level]


file_path = "TestFiles/client_product.txt"
file_content = file_reader.read(file_path)
content_matrix, client_product = file_parser.parse(file_content)
clients = content_matrix[0]
clients_unique = set(clients)
products = content_matrix[1]
products_unique = set(products)

products_occurrences = dict()
for product in products_unique:
    products_occurrences[product] = products.count(product)

clients_shopping_list = []

client_product.sort(key=itemgetter(0))
groups = groupby(client_product, itemgetter(0))

clients_shopping_list = [[key, sorted([item[1] for item in data])] for (key, data) in groups]