Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload script #1

Merged
merged 3 commits into from
Oct 13, 2015
Merged

Upload script #1

merged 3 commits into from
Oct 13, 2015

Conversation

ibrechin
Copy link
Contributor

@ibrechin ibrechin commented Oct 8, 2015

This script will:

  • Retrieve any new data services files from the specified SFTP server and location and save them to a temporary directory
  • Parse these files into the transaction format accepted by the MTP API
  • Upload these transactions to the API
  • Save a file containing the date of the latest file processed for the purposes of only downloading newer data services files

@ibrechin
Copy link
Contributor Author

ibrechin commented Oct 8, 2015

@marcofucci @SteveMarshall give it a review, although it's maybe not a candidate for merging yet as we are still uncertain about how we will be retrieving the files depending on what is going on with the existing MoJ thing

from . import settings

ref_pattern = re.compile('([A-Za-z][0-9]{4}[A-Za-z]{2}).*?([0-9]{1,2}).*?([0-9]{1,2}).*?([0-9]{2,4})')
file_pattern = re.compile('YO1A\.REC\.#D\.(%(code)s)\.D([0-9]{6})' % {'code': settings.ACCOUNT_CODE})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's worth breaking these out using re.VERBOSE and adding some comments to describe the format more clearly?

@SteveMarshall
Copy link
Member

I wonder if there's some way we can do some unit/integration testing of the main uploader? Might be nice to have some guarantees it's doing what it's supposed to… (Though all the code looks good and correct to me, mind you…)

@ibrechin
Copy link
Contributor Author

ibrechin commented Oct 9, 2015

Re: testing, as you probably realised I didn't do much in the way of unit testing because it's basically glue code - it would end up just being data passed between mock objects. Integration testing once we have access to an RBS test environment is probably a good idea though.

os.mkdir(settings.DS_NEW_FILES_DIR)

# check if we recorded date of last file downloaded
last_date = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be worth setting a default, a value really far in the past. This is because the check https://github.com/ministryofjustice/money-to-prisoners-transaction-uploader/pull/1/files#diff-8d4a24f3bb40368c078fa6bfdde77673R56 wouldn't work properly otherwise I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted, although personally I would prefer changing the check to:

if last_date is None or date > last_date

@SteveMarshall
Copy link
Member

This looks good to me! @ibrechin wanna rebase?

This script downloads files which fit a certain format to a temp
directory, and then parses them to extract the relevant transaction
details. These transactions are then uploaded to an API.

Options (listed in settings.py) need to be set as env variables
on the host.
SteveMarshall added a commit that referenced this pull request Oct 13, 2015
Create an initial upload script
@SteveMarshall SteveMarshall merged commit 37d97f8 into master Oct 13, 2015
@SteveMarshall SteveMarshall deleted the uploader branch October 13, 2015 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants