
import datetime as dt
import json

import boto3
import docopt
import maya

args = docopt.docopt(__doc__)

start = maya.parse(args['--start']).datetime()
end = maya.parse(args['--end']).datetime()
minutes = int(args['--interval'] or 30)
resource = args['--resource']

assert resource in ('bibs', 'items')


def generate_windows(start, end, minutes):
    current = start
    while current <= end:
        yield {
            'start': current.isoformat(),
            'end': (current + dt.timedelta(minutes=minutes)).isoformat(),
        }
        current += dt.timedelta(minutes=minutes - 1)


client = boto3.client('sns')

for window in generate_windows(start, end, minutes):
    resp = client.publish(
        TopicArn=f'arn:aws:sns:eu-west-1:760097843905:sierra_{resource}_windows',
        Message=json.dumps(window),
        Subject=f'Window sent by {__file__}'
    )
    print(resp)


import datetime as dt
import json
import math

import boto3
import docopt
import maya
import tqdm

args = docopt.docopt(__doc__)

start = maya.parse(args['--start']).datetime()
end = maya.parse(args['--end']).datetime()
minutes = int(args['--interval'] or 30)
resource = args['--resource']

assert resource in ('bibs', 'items')


def generate_windows(start, end, minutes):
    current = start
    while current <= end:
        yield {
            'start': current.isoformat(),
            'end': (current + dt.timedelta(minutes=minutes)).isoformat(),
        }
        current += dt.timedelta(minutes=minutes - 1)


client = boto3.client('sns')

for window in tqdm.tqdm(
    generate_windows(start, end, minutes),
    total=math.ceil((end - start).total_seconds() / 60 / (minutes - 1))
):
    client.publish(
        TopicArn=f'arn:aws:sns:eu-west-1:760097843905:sierra_{resource}_windows',
        Message=json.dumps(window),
        Subject=f'Window sent by {__file__}'
    )

Print a progress meter when pushing windows
Print a progress meter when pushing windows

  
  import datetime as dt
  import json
+ import math
  
  import boto3
  import docopt
  import maya
+ import tqdm
  
  args = docopt.docopt(__doc__)
  
  start = maya.parse(args['--start']).datetime()
  end = maya.parse(args['--end']).datetime()
  minutes = int(args['--interval'] or 30)
  resource = args['--resource']
  
  assert resource in ('bibs', 'items')
  
  
  def generate_windows(start, end, minutes):
      current = start
      while current <= end:
          yield {
              'start': current.isoformat(),
              'end': (current + dt.timedelta(minutes=minutes)).isoformat(),
          }
          current += dt.timedelta(minutes=minutes - 1)
  
  
  client = boto3.client('sns')
  
+ for window in tqdm.tqdm(
- for window in generate_windows(start, end, minutes):
+     generate_windows(start, end, minutes),
+     total=math.ceil((end - start).total_seconds() / 60 / (minutes - 1))
+ ):
-     resp = client.publish(
+     client.publish(
          TopicArn=f'arn:aws:sns:eu-west-1:760097843905:sierra_{resource}_windows',
          Message=json.dumps(window),
          Subject=f'Window sent by {__file__}'
      )
-     print(resp)
  
Print a progress meter when pushing windows
## Code Before:

import datetime as dt
import json

import boto3
import docopt
import maya

args = docopt.docopt(__doc__)

start = maya.parse(args['--start']).datetime()
end = maya.parse(args['--end']).datetime()
minutes = int(args['--interval'] or 30)
resource = args['--resource']

assert resource in ('bibs', 'items')


def generate_windows(start, end, minutes):
    current = start
    while current <= end:
        yield {
            'start': current.isoformat(),
            'end': (current + dt.timedelta(minutes=minutes)).isoformat(),
        }
        current += dt.timedelta(minutes=minutes - 1)


client = boto3.client('sns')

for window in generate_windows(start, end, minutes):
    resp = client.publish(
        TopicArn=f'arn:aws:sns:eu-west-1:760097843905:sierra_{resource}_windows',
        Message=json.dumps(window),
        Subject=f'Window sent by {__file__}'
    )
    print(resp)

## Instruction:
Print a progress meter when pushing windows
## Code After:

import datetime as dt
import json
import math

import boto3
import docopt
import maya
import tqdm

args = docopt.docopt(__doc__)

start = maya.parse(args['--start']).datetime()
end = maya.parse(args['--end']).datetime()
minutes = int(args['--interval'] or 30)
resource = args['--resource']

assert resource in ('bibs', 'items')


def generate_windows(start, end, minutes):
    current = start
    while current <= end:
        yield {
            'start': current.isoformat(),
            'end': (current + dt.timedelta(minutes=minutes)).isoformat(),
        }
        current += dt.timedelta(minutes=minutes - 1)


client = boto3.client('sns')

for window in tqdm.tqdm(
    generate_windows(start, end, minutes),
    total=math.ceil((end - start).total_seconds() / 60 / (minutes - 1))
):
    client.publish(
        TopicArn=f'arn:aws:sns:eu-west-1:760097843905:sierra_{resource}_windows',
        Message=json.dumps(window),
        Subject=f'Window sent by {__file__}'
    )
