Skip to content
Snippets Groups Projects
Commit c280f3fb authored by George Marchment's avatar George Marchment
Browse files

1st commit

parent 8b71ad76
No related branches found
No related tags found
No related merge requests found
# Github-Crawler
[![MIT licensed](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.liris.cnrs.fr/sharefair/github-crawler.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.liris.cnrs.fr/sharefair/github-crawler/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
## Description
***
This repository contains the code composing a crawler adapted to search for Nextflow workflows on Github.
# Editing this README
The GitHub Search API has a custom rate limit. User-to-server requests are limited to 5,000 requests per hour per authenticated user. The crawler performs the 5,000 requests linearly and is not limited by time; however, after the 5,000 requests, the crawler waits for an hour.
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
The GitHub Search API provides up to 1,000 results for each search, which can be problematic when attempting to compile a large corpus, such as workflows. To circumvent this limitation, the global request to `retrieve Nextflow repositories` is subdivided into multiple requests, each focusing on a specific time frame, such as `retrieve Nextflow repositories between date 1 and date 2`. This process involves incrementing the months and years automatically, ensuring comprehensive coverage of the desired repositories.
## Suggestions for a good README
While the crawler is running, the data is saved in a JSON file.
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
> It's important to note that due to GitHub's search functionality, the results of a search may not be robust, thus the crawler's results may not be reproducible.
## Name
Choose a self-explaining name for your project.
> The current version of the crawler is adapted to work on Nextflow workflows and workflows with at least one Nextflow file at the root of the project. However, it is easy to adapt the crawler to a more generic functionality.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Table of Contents
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
- [Github-Crawler](#github-crawler)
- [Description](#description)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [License](#license)
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
The python function dependancies are described in the `requirements.txt` file.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
## License
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT)
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
___
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
<img align="left" src="img/paris_saclay.png" width="20%">
<img align="left" src="img/lisn.png" width="20%">
<img align="left" src="img/pasteur.png" width="20%">
<img align="left" src="img/sharefair.png" width="20%">
<img align="left" src="img/france2030.png" width="20%">
## License
For open source projects, say how it is licensed.
<br/><br/>
<br/><br/>
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
img/france2030.png

625 KiB

img/lisn.png

22.7 KiB

img/paris_saclay.png

35.3 KiB

img/pasteur.png

76 KiB

img/sharefair.png

479 KiB

from src.crawler import search
search(name='wf_crawl_nextflow.json', start='2017-01-01')
\ No newline at end of file
#Pyhton 3.10.12
PyGithub==2.1.1
python_dateutil==2.8.2
from github import Github, GithubException
import json
import time
from datetime import datetime
from dateutil.relativedelta import relativedelta
g = Github("YOUR API KEY")
def increment_month(x):
return datetime.strptime((x + relativedelta(months=+1)).strftime('%Y-%m-%d'), '%Y-%m-%d')
def date_to_string(x):
return x.strftime('%Y-%m-%d')
def get_repo_content(repo):
return repo.get_contents("")
def get_repo_file(contents):
return contents.pop(0)
def explore_sub_dir_2(repo, path):
return repo.get_contents(path)
#This function increments the number of requests and when it's surpassed waits an hour.
#Limited to 5000 searches per hour
def check_rate(val):
if(val<4990):
return val+1
else:
print("Waiting an hour")
print("1/6")
time.sleep(600)
print("2/6")
time.sleep(600)
print("3/6")
time.sleep(600)
print("4/6")
time.sleep(600)
print("5/6")
time.sleep(600)
print("6/6")
time.sleep(600)
return 0
#If you give this function the json file that already exists it will continue where it last stopped
#The parameter start needs to follow the syntax '%Y-%m-%d'
def search(name='wf_crawl.json', start = '2017-01-01'):
#Define these variables so we can see the progess
nb = 0
#Getting the current date so that the function knows when to stop
today= datetime.today()
#Setting the date to start searching
date_working= datetime.strptime(start, '%Y-%m-%d')
#Defining the structure to save the data and right the json file later on
wf_crawl = {}
#Recuparating the data that already exist to continue where we left off
#If the file is in the same directory
try:
with open(name) as json_file:
#Read the file
json_data = json.load(json_file)
#Recuparate the last working date
date_working = datetime.strptime(json_data['last_date']['date'][0], '%Y-%m-%d')
#Remove the working date
json_data.pop('last_date', None)
#Set the data
wf_crawl= json_data.copy()
except:
print("Either the file doesn't exist or I coudn't read it. So i'm starting from 0.")
val=0
#For every date till today
while(date_working<today):
#Updating the day since it's possible that the crawler takes longer than a day
today= datetime.today()
#Getting the time interval to search
first_date= date_to_string(date_working)
date_working= increment_month(date_working)
second_date= date_to_string(date_working)
#Defining the
#https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax
query=f"nextflow created:{first_date}..{second_date}"
#Retrieving the repositories
result = g.search_repositories(query)
val=check_rate(val)
#Getting the number of repositories
nb_result= result.totalCount
#Adding them to the total
nb+=nb_result
#index
index=0
#Print
print(f'Between {first_date} and {second_date} : ')
#For each repositories
for repo in result:
index+=1
print(f'Working on {index}/{nb_result}')
try :
# 1st request to GitHub
#Getting the contents of the repositories
#Check if there is an .nf file at the root of the project
#This is a way to check is the repo decribes a pipeline or not
nextflow_file_in_root = False
content = repo.get_contents("")
for file in content:
if(file.path[-3:]=='.nf'):
nextflow_file_in_root = True
val=check_rate(val)
if(nextflow_file_in_root):
#Checking if there is a License
if(repo.license!=None):
#Adding the different information to the json file
wf_crawl[repo.full_name] = {}
#Name of the workflow
#Since the format given is : 'owner/name'
wf_crawl[repo.full_name]['name'] = str(repo.full_name).split('/')[1]
#Creation date
wf_crawl[repo.full_name]['creation_date'] = date_to_string(repo.created_at)
#Actual date (date when creating the json)
wf_crawl[repo.full_name]['actual_date'] = date_to_string(today)
#Owner
wf_crawl[repo.full_name]['owner'] = repo.owner.login
#Contributors
wf_crawl[repo.full_name]['contributors'] = repo.contributors_url
#Description
wf_crawl[repo.full_name]['description'] = repo.description
#Nb forks
wf_crawl[repo.full_name]['forks'] = repo.forks
#Nb stars
wf_crawl[repo.full_name]['stars'] = repo.stargazers_count
#License
wf_crawl[repo.full_name]['license'] = repo.license.name
#Commits
val=check_rate(val)
commits = list(repo.get_commits())
val=check_rate(val)
wf_crawl[repo.full_name]['last_commit_date'] = date_to_string(commits[0].commit.author.date)
val=check_rate(val)
wf_crawl[repo.full_name]['last_commit_id'] = str(commits[0].commit._identity)
val=check_rate(val)
wf_crawl[repo.full_name]['first_commit_date'] = date_to_string(commits[-1].commit.author.date)
val=check_rate(val)
wf_crawl[repo.full_name]['first_commit_id'] = str(commits[-1].commit._identity)
val=check_rate(val)
wf_crawl[repo.full_name]['nb_commmits'] = len(commits)
val=check_rate(val)
else:
nb=-1
except GithubException as error:
print(error)
break
#Showing the progress
print(f'Between {first_date} and {second_date}, found {nb_result} repo(s), total repo(s): {nb}')
#Witing the results into the json file
#Writting the json file
with open(name, 'w') as output_file :
#We add the last last working date to be able continue where the crawler last stopped
temp = wf_crawl.copy()
last_date= second_date
if(date_working>today):
last_date =date_to_string(today)
temp['last_date'] = {'date':[last_date]}
json.dump(temp, output_file, indent=4)
{
"HadrienG/nextflow_rna": {
"name": "nextflow_rna",
"creation_date": "2017-01-10",
"actual_date": "2024-02-15",
"owner": "HadrienG",
"contributors": "https://api.github.com/repos/HadrienG/nextflow_rna/contributors",
"description": null,
"forks": 0,
"stars": 0,
"license": "GNU General Public License v3.0",
"last_commit_date": "2017-01-10",
"last_commit_id": "340532398a54ec0bab2c4a1cb965e1a04c0ce5e4",
"first_commit_date": "2017-01-10",
"first_commit_id": "4589ffee56c8a152d9baecdb8301a2dd29cb59eb",
"nb_commmits": 2
},
"IARCbioinfo/CODEX-nf": {
"name": "CODEX-nf",
"creation_date": "2017-01-16",
"actual_date": "2024-02-15",
"owner": "IARCbioinfo",
"contributors": "https://api.github.com/repos/IARCbioinfo/CODEX-nf/contributors",
"description": "Pipeline for copy number variant calling from Whole Exome sequencing data using CODEX",
"forks": 2,
"stars": 2,
"license": "GNU General Public License v3.0",
"last_commit_date": "2017-03-01",
"last_commit_id": "3579ec0877515ff247e03e1dafe911c782412346",
"first_commit_date": "2017-01-16",
"first_commit_id": "0ca2a91487490bc79b25c2b6d6348fae1598372e",
"nb_commmits": 37
},
"AndersenLab/ril-nf": {
"name": "ril-nf",
"creation_date": "2017-01-08",
"actual_date": "2024-02-15",
"owner": "AndersenLab",
"contributors": "https://api.github.com/repos/AndersenLab/ril-nf/contributors",
"description": null,
"forks": 1,
"stars": 1,
"license": "MIT License",
"last_commit_date": "2017-10-16",
"last_commit_id": "c33ee40934f2868a352d96cb2deb8b5ccbddbdac",
"first_commit_date": "2016-12-14",
"first_commit_id": "40e4de22c26e10a5b7494cb21960002d09abcbb0",
"nb_commmits": 118
},
"robsyme/markerdev": {
"name": "markerdev",
"creation_date": "2017-01-25",
"actual_date": "2024-02-15",
"owner": "robsyme",
"contributors": "https://api.github.com/repos/robsyme/markerdev/contributors",
"description": "A nextflow pipeline for developing markers that differentiate one set of individuals from another.",
"forks": 0,
"stars": 0,
"license": "MIT License",
"last_commit_date": "2017-01-25",
"last_commit_id": "5f615cbdf7eba3b5ac465fa7077d5071ac0fe744",
"first_commit_date": "2017-01-25",
"first_commit_id": "ff89e9353e0151e3e24f188455a8c17f8e52050e",
"nb_commmits": 2
},
"CRG-CNAG/CalliNGS-NF": {
"name": "CalliNGS-NF",
"creation_date": "2017-02-28",
"actual_date": "2024-02-15",
"owner": "CRG-CNAG",
"contributors": "https://api.github.com/repos/CRG-CNAG/CalliNGS-NF/contributors",
"description": "GATK RNA-Seq Variant Calling in Nextflow",
"forks": 51,
"stars": 128,
"license": "Mozilla Public License 2.0",
"last_commit_date": "2021-08-25",
"last_commit_id": "9e7ebf04455a24877a92c87216b9629ee2b6088d",
"first_commit_date": "2017-02-28",
"first_commit_id": "b6cc78c991a894646f2ddaa4304e48adaf4f66cf",
"nb_commmits": 171
},
"ctmrbio/BACTpipe": {
"name": "BACTpipe",
"creation_date": "2017-02-27",
"actual_date": "2024-02-15",
"owner": "ctmrbio",
"contributors": "https://api.github.com/repos/ctmrbio/BACTpipe/contributors",
"description": "BACTpipe: An assembly and annotation pipeline for bacterial genomics",
"forks": 7,
"stars": 20,
"license": "MIT License",
"last_commit_date": "2022-09-06",
"last_commit_id": "63734656cb6ea3e8b2387a531e1d2881dccfeca3",
"first_commit_date": "2017-09-06",
"first_commit_id": "84409b618b65fd6305721c2dda3b67c60afc3090",
"nb_commmits": 510
},
"danielecook/nextflow-tutorial": {
"name": "nextflow-tutorial",
"creation_date": "2017-02-07",
"actual_date": "2024-02-15",
"owner": "danielecook",
"contributors": "https://api.github.com/repos/danielecook/nextflow-tutorial/contributors",
"description": null,
"forks": 0,
"stars": 0,
"license": "MIT License",
"last_commit_date": "2017-02-15",
"last_commit_id": "8b6e052f939605dd91c1c2b65c649710412d6d79",
"first_commit_date": "2017-02-07",
"first_commit_id": "6e53545dab0f7aef524baf171be7650b15cda778",
"nb_commmits": 13
},
"IARCbioinfo/bamsurgeon-nf": {
"name": "bamsurgeon-nf",
"creation_date": "2017-02-21",
"actual_date": "2024-02-15",
"owner": "IARCbioinfo",
"contributors": "https://api.github.com/repos/IARCbioinfo/bamsurgeon-nf/contributors",
"description": "bamsurgeon with step of variant simulation encapsulated with nextflow",
"forks": 1,
"stars": 1,
"license": "GNU General Public License v3.0",
"last_commit_date": "2019-03-01",
"last_commit_id": "de9138f7dc9192b9adee5595bad9e4fe03782634",
"first_commit_date": "2017-02-21",
"first_commit_id": "a4657254417e9f09f850e4cdc45c3b8ee4aed579",
"nb_commmits": 7
},
"last_date": {
"date": [
"2017-03-01"
]
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment