Esempio n. 1
0
    def on_mount(self) -> None:
        """ This method runs when the component is first mounted on the page. It
        uses the fetch API to retrieve some todo items from an API. Then, it will
        add the retrieved items to the state of this component so they get rendered.
        """
        def create_initial_todos(data: str) -> None:
            """ Helper method to parse a string as JSON data and convert the data into
            todo items.

            Args:
                data (str): The raw JSON string to parse
            """

            # Parse as JSON (only use the first 2 todo items)
            items = json.loads(data)[:2]

            # Set the state to the newly retrieved items
            self.set_state(
                "todolist",
                [
                    TodoItem(title=item["title"], is_done=True)
                    for item in items
                ],
            )

        # Use the fetch API to retrieve some sample todos
        fetch("https://jsonplaceholder.typicode.com/todos").then(
            create_initial_todos)
Esempio n. 2
0
def callme(response):
	global callbacks
	global data
	d = main.fetch(response.body)
	if d!=False:
		data.append(d)
	callbacks+=1
	you_handle()
Esempio n. 3
0
def cmd():
    args = docopt.docopt(__doc__)

    workdir = args['--workdir']
    if workdir:
        if not os.path.isdir(main.expand_workdir(workdir)):
            print >>sys.stderr, "Won't create the workdir for you!"
            raise SystemExit
    else:
        workdir = os.getcwd()

    org = main.get_organization(args['<organization>'], workdir)
    if args['--only-repo']:
        repos = [org.get_repo(args['--only-repo'])]
    else:
        repos = org.get_repos()

    if args['init']:
        main.init_repos(repos, workdir)

    if args['sync']:
        main.fetch(repos, workdir)
Esempio n. 4
0
def cmd():
    args = docopt.docopt(__doc__)

    workdir = args['--workdir']
    if workdir:
        if not os.path.isdir(main.expand_workdir(workdir)):
            print >> sys.stderr, "Won't create the workdir for you!"
            raise SystemExit
    else:
        workdir = os.getcwd()

    org = main.get_organization(args['<organization>'], workdir)
    if args['--only-repo']:
        repos = [org.get_repo(args['--only-repo'])]
    else:
        repos = org.get_repos()

    if args['init']:
        main.init_repos(repos, workdir)

    if args['sync']:
        main.fetch(repos, workdir)
Esempio n. 5
0
def test_fetch_warning_urls_publishes_fetched_article_with_issues(url):

    sleep(PAUSE_INTERVAL)

    event = SavedNewRequestedArticle(id=str(uuid4()), url=url)
    message, ctx = gcf_encoding(event.to_json(), {})

    ret = None
    with patch("env.publish") as publish:
        ret = fetch(message, ctx)

    assert ret == ""
    publish.assert_called_once()
    assert_serialized_event(SucceededFetchingArticleWithIssues, publish.call_args[0][0])
Esempio n. 6
0
def fetch_instances():
    start_date = datetime.fromtimestamp(int(request.args.get('_startDate'))/1000.0).date()
    end_date = datetime.fromtimestamp(int(request.args.get('_endDate'))/1000.0).date() + timedelta(days=1)

    print("* Fetching instances - from: " + str(start_date) + " ,to: " + str(end_date))

    # Load credentials from the session.
    credentials = google.oauth2.credentials.Credentials(
        **flask.session['credentials'])
    service = googleapiclient.discovery.build(
        API_SERVICE_NAME, API_VERSION, credentials=credentials)

    data = main.fetch(start_date.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),end_date.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
                      service=service)

    return jsonify(data)
Esempio n. 7
0
def test_fetch_blocked_unknown_urls_publishes_failed_fetching_article_and_throws_error(
    url
):

    sleep(PAUSE_INTERVAL)

    event = SavedNewRequestedArticle(id=str(uuid4()), url=url)
    message, ctx = gcf_encoding(event.to_json(), {})

    ret = None
    with patch("env.publish") as publish:
        with pytest.raises(FetchError):
            ret = fetch(message, ctx)

    assert ret is None
    publish.assert_called_once()
    assert_serialized_event(FailedFetchingArticle, publish.call_args[0][0])
Esempio n. 8
0
def callme(response):
	global callbacks
	global data
	data.append(main.fetch(response.body))
	callbacks+=1
	you_handle()
Esempio n. 9
0
import timeit
# import math

start_roll_no=input('Enter first roll no:')
last_roll_no=input('Enter last roll no:')

file_name=raw_input('File in which data should be stored [default is data.json]:')
if file_name=='':
	file_name='data.json'
elif len(file_name.split('.'))<2:
	file_name+='.json'
data={}

if start_roll_no>last_roll_no:
	tmp=start_roll_no
	start_roll_no=last_roll_no
	last_roll_no=tmp
roll_no=start_roll_no

start = timeit.default_timer()
while roll_no<=last_roll_no:
	info=main.fetch(roll_no)
	if info:
		data[roll_no]=info
	roll_no+=1

stop = timeit.default_timer()
print 'Time take is '+str(int(stop - start))+' For '+str(last_roll_no - start_roll_no+1)+' persons'
print 'Data is stored in data/',file_name
json_file=open('data/'+file_name,'w')
json_file.write(json.dumps(data,sort_keys=True,indent=4,separators=(',',': ')))
Esempio n. 10
0
last_roll_no = input('Enter last roll no:')

file_name = raw_input(
    'File in which data should be stored [default is data.json]:')
if file_name == '':
    file_name = 'data.json'
elif len(file_name.split('.')) < 2:
    file_name += '.json'
data = {}

if start_roll_no > last_roll_no:
    tmp = start_roll_no
    start_roll_no = last_roll_no
    last_roll_no = tmp
roll_no = start_roll_no

start = timeit.default_timer()
while roll_no <= last_roll_no:
    info = main.fetch(roll_no)
    if info:
        data[roll_no] = info
    roll_no += 1

stop = timeit.default_timer()
print 'Time take is ' + str(
    int(stop - start)) + ' For ' + str(last_roll_no - start_roll_no +
                                       1) + ' persons'
print 'Data is stored in data/', file_name
json_file = open('data/' + file_name, 'w')
json_file.write(
    json.dumps(data, sort_keys=True, indent=4, separators=(',', ': ')))