Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. import pandas as pd
  2. import configparser
  3. import pymssql
  4.  
  5. config = configparser.ConfigParser()
  6. config.read('settings.txt')
  7.  
  8. conn = pymssql.connect(server=config.get('Connection', 'server'),
  9.                        user=config.get('Connection', 'user'),
  10.                        password=config.get('Connection', 'password'),
  11.                        database=config.get('Connection', 'database'))
  12. print('Connection established')
  13.  
  14. core = pd.DataFrame(columns=['Supplier reference',
  15.                              'Customer PO',
  16.                              'No',
  17.                              'Cross Reference',
  18.                              'Code',
  19.                              'Description',
  20.                              'Quantity',
  21.                              'Unit of Measure',
  22.                              'Plant',
  23.                              'Storage location',
  24.                              'Price, $',
  25.                              'Batch',
  26.                              'Amount, $',
  27.                              'Country of Origin PANIN'])
  28.  
  29. query = config.get('Queries', 'reg_orders')
  30. df = pd.read_sql(query, conn)
  31. df['No'] = (df.groupby('TaskId').cumcount() + 1) * 10
  32.  
  33. orders_list = df['TaskId'].unique().tolist()
  34. print('Total orders: {}'.format(len(orders_list)))
  35.  
  36. for i in orders_list:
  37.     temp_df = df.loc[df['TaskId'] == i]
  38.     file_name = '{}{}{}{}_{}.xlsx'.format(
  39.         config.get('Destination', 'output_path'),
  40.         temp_df.get_value(0, 'OrderName'),
  41.         temp_df.get_value(0, 'RecepientDescription'),
  42.         temp_df.get_value(0, 'IssuerDescription'),
  43.         temp_df.get_value(0, 'IssuerPlant'))
  44.     core['No'], core['Code'] = temp_df['No'], temp_df['Material']
  45.     core['Quantity'], core['Plant'] = temp_df['Q'], temp_df['IssuerPlant']
  46.     core['Storage location'] = temp_df['StLoc']
  47.     writer = pd.ExcelWriter(file_name, engine='xlsxwriter')
  48.     core.to_excel(writer, sheet_name='Sheet1', index=False)
  49.     writer.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement