Skip to content

Instantly share code, notes, and snippets.

@allaway
Created April 24, 2024 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allaway/279d2171b1a53c8f3aa0fb65772b86df to your computer and use it in GitHub Desktop.
Save allaway/279d2171b1a53c8f3aa0fb65772b86df to your computer and use it in GitHub Desktop.
ChatGPT-generated script to change portal data status based on data present (not tested yet)
import synapseclient
import pandas as pd
# Constants for the views
FILE_VIEW_ID = "syn16858331"
PROJECT_VIEW_ID = "syn52677631"
def main():
syn = synapseclient.Synapse()
syn.login('YourUsername', 'YourPassword', rememberMe=True)
# Fetch the project view data
projects_df = syn.tableQuery(f'SELECT * FROM {PROJECT_VIEW_ID}').asDataFrame()
# Filter for projects with 'Data Pending'
pending_projects = projects_df[projects_df['dataStatus'] == 'Data Pending']
# Fetch the file view data
fileview_df = syn.tableQuery(f'SELECT * FROM {FILE_VIEW_ID} WHERE contentType="file" AND resourceType LIKE "%experimentalData%"').asDataFrame()
# Iterate through pending projects
for idx, project in pending_projects.iterrows():
# Check for associated experimental data files
related_files = fileview_df[fileview_df['projectId'] == project['id']]
if not related_files.empty:
# Update the project dataStatus to 'Under Embargo'
project['dataStatus'] = 'Under Embargo'
syn.store(synapseclient.Project(id=project['id'], annotations=project))
if __name__ == "__main__":
main()
@allaway
Copy link
Author

allaway commented Apr 24, 2024

ChatGPT github action:

name: Synapse Data Update

on:
  schedule:
    - cron: '0 0 * * *'  # Runs every day at midnight

jobs:
  update-data-status:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.8'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install synapseclient pandas
    - name: Run the script
      run: python update_synapse_data.py
      env:
        SYNAPSE_AUTH_TOKEN: ${{ secrets.SYNAPSE_AUTH_TOKEN }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment