예제 #1
0
def main(noradID, path):

    st = SpaceTrackClient('*****@*****.**', 'COSGCGroundSegment')

    try:
        st.authenticate()  # Will raise an error if incorrect login
    except:
        print('Incorrect Login.')
        sys.exit(0)

    data = st.tle_latest(iter_lines=True,
                         norad_cat_id=noradID,
                         limit=1,
                         format='3le')
    # Change format to whatever is easiest

    line1 = next(data)  # 0 MINXSS
    line2 = next(data)  # 1 blah blah
    line3 = next(data)  # 2 blah blah

    outFile = path + line1.split()[1] + '.txt'

    # Need to split up the generator to get the name for above.
    with open(outFile, 'w+') as f:
        f.write(line1)
        f.write(line2)
        f.write(line3)
예제 #2
0
def test_base_url():
    responses.add(responses.POST,
                  'https://example.com/ajaxauth/login',
                  json='""')
    st = SpaceTrackClient('identity',
                          'password',
                          base_url='https://example.com')
    st.authenticate()

    assert len(responses.calls) == 1
예제 #3
0
def download_tle():
    """
    Because the API is unstable, we can download it for testing
    """
    user = ""
    password = ""
    c = SpaceTrackClient(user, password)
    c.authenticate()
    data = c.get_space_debris()
    with open('tle.txt', 'w') as f:
        f.write(data)
    c.close()
예제 #4
0
def test_authenticate():
    def request_callback(request):
        if 'wrongpassword' in request.body:
            return (200, dict(), json.dumps({'Login': '******'}))
        elif 'unknownresponse' in request.body:
            # Space-Track doesn't respond like this, but make sure anything
            # other than {'Login': '******'} doesn't raise AuthenticationError
            return (200, dict(), json.dumps({'Login': '******'}))
        else:
            return (200, dict(), json.dumps(''))

    responses.add_callback(responses.POST,
                           'https://www.space-track.org/ajaxauth/login',
                           callback=request_callback,
                           content_type='application/json')

    st = SpaceTrackClient('identity', 'wrongpassword')

    with pytest.raises(AuthenticationError):
        st.authenticate()

    assert len(responses.calls) == 1

    st.password = '******'
    st.authenticate()
    st.authenticate()

    # Check that only one login request was made since successful
    # authentication
    assert len(responses.calls) == 2

    st = SpaceTrackClient('identity', 'unknownresponse')
    st.authenticate()
예제 #5
0
def test_authenticate():
    def request_callback(request):
        if 'wrongpassword' in request.body:
            return (200, dict(), json.dumps({'Login': '******'}))
        elif 'unknownresponse' in request.body:
            # Space-Track doesn't respond like this, but make sure anything
            # other than {'Login': '******'} doesn't raise AuthenticationError
            return (200, dict(), json.dumps({'Login': '******'}))
        else:
            return (200, dict(), json.dumps(''))

    responses.add_callback(
        responses.POST, 'https://www.space-track.org/ajaxauth/login',
        callback=request_callback, content_type='application/json')

    st = SpaceTrackClient('identity', 'wrongpassword')

    with pytest.raises(AuthenticationError):
        st.authenticate()

    assert len(responses.calls) == 1

    st.password = '******'
    st.authenticate()
    st.authenticate()

    # Check that only one login request was made since successful
    # authentication
    assert len(responses.calls) == 2

    st = SpaceTrackClient('identity', 'unknownresponse')
    st.authenticate()
예제 #6
0
def main(noradID, path):

    st = SpaceTrackClient('*****@*****.**', 'COSGCGroundSegment')

    try:
        st.authenticate() # Will raise an error if incorrect login
    except:
        print('Incorrect Login.')
        sys.exit(0)

    data = st.tle_latest(iter_lines=True, norad_cat_id=noradID, limit=1, format='3le')
    # Change format to whatever is easiest
    
    line1 = next(data) # 0 MINXSS
    line2 = next(data) # 1 blah blah
    line3 = next(data) # 2 blah blah
    
    outFile = path + line1.split()[1] + '.txt'

    # Need to split up the generator to get the name for above. 
    with open(outFile, 'w+') as f:
        f.write(line1)
        f.write(line2)
        f.write(line3)