Ping the Web
Try for free
No credit card required
Go to Store
Ping the Web
canadesk/ping-web
Try for free
No credit card required
A simple endpoint to ping servers (OK/KO).
.actor/Dockerfile
1# First, specify the base Docker image.
2# You can see the Docker images from Apify at https://hub.docker.com/r/apify/.
3# You can also use any other image from Docker Hub.
4FROM apify/actor-python:3.11
5
6# Second, copy just requirements.txt into the actor image,
7# since it should be the only file that affects the dependency install in the next step,
8# in order to speed up the build
9COPY requirements.txt ./
10
11# Install the packages specified in requirements.txt,
12# Print the installed Python version, pip version
13# and all installed packages with their versions for debugging
14RUN echo "Python version:" \
15 && python --version \
16 && echo "Pip version:" \
17 && pip --version \
18 && echo "Installing dependencies:" \
19 && pip install -r requirements.txt \
20 && echo "All installed Python packages:" \
21 && pip freeze
22
23# Next, copy the remaining files and directories with the source code.
24# Since we do this after installing the dependencies, quick build will be really fast
25# for most source file changes.
26COPY . ./
27
28# Specify how to launch the source code of your actor.
29# By default, the "python3 -m src" command is run
30CMD ["python3", "-m", "src"]
.actor/actor.json
1{
2 "actorSpecification": 1,
3 "name": "ping-the-web",
4 "title": "Ping the Web",
5 "description": "Ping the Web.",
6 "version": "1.0",
7 "meta": {
8 "templateId": "python-beautifulsoup"
9 },
10 "input": "./input_schema.json",
11 "dockerfile": "./Dockerfile"
12}
.actor/input_schema.json
1{
2 "title": "Ping the Web",
3 "type": "object",
4 "schemaVersion": 1,
5 "properties": {
6 "url": {
7 "title": "URL",
8 "type": "string",
9 "description": "The website you want to test. Do not include the protocol.",
10 "prefill": "google.com",
11 "editor": "textfield"
12 }
13 },
14 "required": ["url"]
15}
src/main.py
1from apify import Actor
2from icmplib import ping
3
4def host_up(hostname:str):
5 host = ping(hostname, count=5, interval=0.2)
6 print(host)
7 return host.is_alive
8
9async def main():
10 async with Actor:
11 actor_input = await Actor.get_input() or {}
12 # Structure of input is defined in .actor/input_schema.json
13 host = actor_input.get('url')
14 response = "KO"
15
16 try:
17 if host_up(host):
18 response = "OK"
19 print(f"{host} - Connection successful!")
20 except:
21 print(f"{host} - Connection failed...")
22 response = "KO"
23
24 await Actor.push_data([
25 {
26 'result': response
27 },
28 ])
.dockerignore
1# configurations
2.idea
3
4# crawlee and apify storage folders
5apify_storage
6crawlee_storage
7storage
8
9# installed files
10.venv
11
12# git folder
13.git
.editorconfig
1root = true
2
3[*]
4indent_style = space
5indent_size = 4
6charset = utf-8
7trim_trailing_whitespace = true
8insert_final_newline = true
9end_of_line = lf
.gitignore
1# This file tells Git which files shouldn't be added to source control
2
3.idea
4.DS_Store
5
6apify_storage
7storage
8
9.venv/
10.env/
11__pypackages__
12dist/
13build/
14*.egg-info/
15*.egg
16
17__pycache__
18
19.mypy_cache
20.dmypy.json
21dmypy.json
22.pytest_cache
23
24.scrapy
25*.log
requirements.txt
1# Add your dependencies here.
2# See https://pip.pypa.io/en/latest/reference/requirements-file-format/
3# for how to format them
4apify ~= 1.1.1
5icmplib
Developer
Maintained by Community
Actor Metrics
1 monthly user
-
1 star
>99% runs succeeded
Created in Aug 2023
Modified a year ago
Categories