Automated post generation for X.com
- Install Ollama with Llama3.2:
curl -fsSL https://ollama.com/install.sh | sh - Run Llama3.2:
ollama run llama3.2
Follow these steps to get started with automated post generation for X.com:
First, clone the repository to your local machine:
git clone <repository-url>
cd HelloAiCreate a .env file in the root directory and provide your Twitter API credentials:
API_KEY=<your-api-key>
API_SECRET=<your-api-secret>
ACCESS_TOKEN=<your-access-token>
ACCESS_SECRET=<your-access-secret>
Ensure you replace the placeholders with your actual credentials.
Use poetry to install the required dependencies:
poetry installNow you can run the script to generate and post tweets every hour:
poetry run python main.pyThe application uses Llama3.2 to generate tweets about semiconductors and automatically posts them to X.com (Twitter). Make sure your Twitter credentials are valid and that you have the necessary permissions.
- The
.envfile should never be committed to the repository to keep your credentials safe. - The script will run indefinitely, posting a tweet every hour. You can stop it anytime by pressing
Ctrl + C.
To get your API Key, API Secret, Access Token, and Bearer Token from the X platform (formerly Twitter), follow these steps:
-
Create a Developer Account:
- Go to the Twitter Developer Portal and sign in with your X account.
- If you haven't already, apply for a developer account by filling in the required details. This will include specifying the intended use of the API and agreeing to their terms.
-
Create a Project and App:
- Once you're approved as a developer, navigate to the "Projects & Apps" section and create a new project if you don’t have one.
- Inside the project, create an app by giving it a name and selecting the relevant permissions (like read, write, and direct messages if needed).
-
Generate API Keys and Tokens:
- Once your app is created, go to the "Keys and tokens" section of the app.
- Here, you’ll find the API Key and API Secret Key. You can also generate the Bearer Token.
- Scroll down to the "Access Token & Secret" section. You might need to generate these by clicking on "Generate".
-
Store Your Keys Securely:
- After generating these keys and tokens, store them securely. For example, you can put them in a
.envfile as you have shown in your image for use in your applications.
- After generating these keys and tokens, store them securely. For example, you can put them in a
Remember, be careful not to expose these credentials publicly, as they can be used to access your account’s API functions.
If by accident you do commit your .env file, here is how to remove it from your history. 😊 Happy coding! 🚀
The issue is due to Git retaining the .env file in the history of your branch, even after adding it to .gitignore and deleting it locally. .gitignore only prevents new files from being added to commits, but it doesn’t retroactively remove files that have already been committed. Here’s how you can resolve this by removing the .env file from your branch history:
To remove the .env file from the history of your branch, follow these steps:
-
Remove the file from the Git history:
- Use the
git rmcommand with the--cachedflag to remove the.envfile from the Git index without deleting it from your local file system.git rm --cached frontend/X/.env
- Use the
-
Commit the Change:
- Commit the change to record the removal of the file.
git commit -m "Remove .env file from history"
- Commit the change to record the removal of the file.
-
Remove the File from All Previous Commits:
- To erase the
.envfile from all previous commits, use thefilter-branchcommand, which rewrites the history:git filter-branch --force --index-filter \ 'git rm --cached --ignore-unmatch frontend/X/.env' \ --prune-empty --tag-name-filter cat -- --all
- To erase the
-
Force Push the Changes to Remote:
- Since this rewrites commit history, you’ll need to force-push to the branch to update it on the remote repository.
git push origin your-branch-name --force
- Since this rewrites commit history, you’ll need to force-push to the branch to update it on the remote repository.
-
Verify and Clean Up:
- After pushing, check that the
.envfile is no longer present in the history. Optionally, you can run garbage collection to remove any lingering references:git gc --prune=now --aggressive
- After pushing, check that the
Warning: Force-pushing rewritten history affects anyone else working on the branch, so ensure no one else has pulled this branch or notify team members beforehand.
After you’ve removed the .env file, consider rotating any keys or sensitive information that was included in it, as they may have been exposed in the commit history before this removal.