├── .github
├── SUPPORT.md
├── CONTRIBUTING.md
├── FUNDING.yml
├── SECURITY.md
├── dependabot.yml
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
└── workflows
│ ├── ci.yml
│ └── codacy-analysis.yml
├── assets
├── help.md
├── start.md
├── about.md
├── POD.png
├── POM.png
├── description.md
└── commands.md
├── .gitignore
├── .env.example
├── requirements.txt
├── README.md
├── LICENSE
└── Product_Hunt_bot.py
/.github/SUPPORT.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/assets/help.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/assets/start.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .env
2 | *.json
--------------------------------------------------------------------------------
/assets/about.md:
--------------------------------------------------------------------------------
1 | A bot for Telegram that sends you daily updates from Product Hunt 😺
2 |
--------------------------------------------------------------------------------
/assets/POD.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Crazy-Marvin/ProductHuntTelegramBot/HEAD/assets/POD.png
--------------------------------------------------------------------------------
/assets/POM.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Crazy-Marvin/ProductHuntTelegramBot/HEAD/assets/POM.png
--------------------------------------------------------------------------------
/assets/description.md:
--------------------------------------------------------------------------------
1 | Get notified about new posts on Product Hunt and discover nice products 😺
2 |
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | API_KEY = "123456789abcdefghijklmnopqrstuvwxyz"
2 | ph_auth = "123456789"
3 | my_id = '123456789'
4 | analyst_id = '123456789'
5 | creds_location = 'place'
6 | forms_url = 'forms.google.com'
7 | spreadsheets_url = 'spreadsheets.google.com'
8 | healthchecks = 'https://hc-ping.com/db123456-789a-12ab-aaaa-sssssssssssssss'
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | autopep8
2 | cachetools
3 | certifi
4 | charset-normalizer
5 | google-auth
6 | google-auth-oauthlib
7 | gspread
8 | httplib2
9 | idna
10 | oauth2client
11 | oauthlib
12 | pyasn1
13 | pyasn1-modules
14 | pycodestyle
15 | pyparsing
16 | pyTelegramBotAPI
17 | python-dotenv
18 | requests
19 | requests-oauthlib
20 | rsa
21 | schedule
22 | six
23 | toml
24 | urllib3
25 |
--------------------------------------------------------------------------------
/assets/commands.md:
--------------------------------------------------------------------------------
1 | start - This starts the bot 🚀
2 | daily - This sends all products of the day 🗣
3 | monthly - This sends all products of the month 🗣
4 | schedule - This lets you choose a schedule for automatic updates 🕰
5 | help - This sends you a help text 🆘
6 | contact - This allows contact ✍️
7 | feedback - This lets you give feedback 👺
8 | privacy - This sends you Terms and Privacy Policy 🔐
9 |
--------------------------------------------------------------------------------
/.github/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Supported Versions
4 |
5 | The latest version might be supported with security updates.
6 |
7 | ## Reporting a Vulnerability
8 |
9 | Use this section to tell people how to report a vulnerability.
10 |
11 | Tell them where to go, how often they can expect to get an update on a
12 | reported vulnerability, what to expect if the vulnerability is accepted or
13 | declined, etc.
14 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: "pip" # See documentation for possible values
9 | directory: "/" # Location of package manifests
10 | schedule:
11 | interval: "monthly"
12 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 |
5 | ---
6 |
7 | ## :writing_hand: Describe the bug
8 |
9 |
10 | ## :bomb: Steps to reproduce
11 |
12 | 1. Go to '...'
13 | 2. Click on '....'
14 | 3. Scroll down to '....'
15 | 4. See error
16 |
17 | ## :wrench: Expected behavior
18 |
19 |
20 | ## :camera: Screenshots
21 |
22 |
23 | ## :iphone: Tech info
24 | - Device:
25 | - OS:
26 | - App Version:
27 |
28 | ## :page_facing_up: Additional context
29 |
30 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 |
5 | ---
6 |
7 | ## :warning: Is your feature request related to a problem? Please describe
8 |
9 |
10 | ## :bulb: Describe the solution you'd like
11 |
12 |
13 | ## :bar_chart: Describe alternatives you've considered
14 |
15 |
16 | ## :page_facing_up: Additional context
17 |
18 |
19 | ## :raising_hand: Do you want to develop this feature yourself?
20 |
21 | - [ ] Yes
22 | - [ ] No
23 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | # This workflow will install Python dependencies, run tests and lint with a single version of Python
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3 |
4 | name: CI
5 |
6 | on:
7 | push:
8 | branches: [ development ]
9 | pull_request:
10 | branches: [ development ]
11 |
12 | jobs:
13 | build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - uses: actions/checkout@v2
19 | - name: Set up Python 3.9
20 | uses: actions/setup-python@v2
21 | with:
22 | python-version: 3.9
23 | - name: Install dependencies
24 | run: |
25 | python -m pip install --upgrade pip
26 | pip install flake8 pytest
27 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28 | - name: Lint with flake8
29 | run: |
30 | # stop the build if there are Python syntax errors or undefined names
31 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
32 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
33 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
34 | - name: Test with pytest
35 | run: |
36 | pytest
37 |
--------------------------------------------------------------------------------
/.github/workflows/codacy-analysis.yml:
--------------------------------------------------------------------------------
1 | # This workflow checks out code, performs a Codacy security scan
2 | # and integrates the results with the
3 | # GitHub Advanced Security code scanning feature. For more information on
4 | # the Codacy security scan action usage and parameters, see
5 | # https://github.com/codacy/codacy-analysis-cli-action.
6 | # For more information on Codacy Analysis CLI in general, see
7 | # https://github.com/codacy/codacy-analysis-cli.
8 |
9 | name: Codacy Security Scan
10 |
11 | on:
12 | push:
13 | branches: [ development ]
14 | pull_request:
15 | # The branches below must be a subset of the branches above
16 | branches: [ development ]
17 | schedule:
18 | - cron: '24 4 * * 6'
19 |
20 | jobs:
21 | codacy-security-scan:
22 | name: Codacy Security Scan
23 | runs-on: ubuntu-latest
24 | steps:
25 | # Checkout the repository to the GitHub Actions runner
26 | - name: Checkout code
27 | uses: actions/checkout@v2
28 |
29 | # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
30 | - name: Run Codacy Analysis CLI
31 | uses: codacy/codacy-analysis-cli-action@1.1.0
32 | with:
33 | # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
34 | # You can also omit the token and run the tools that support default configurations
35 | project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
36 | verbose: true
37 | output: results.sarif
38 | format: sarif
39 | # Adjust severity of non-security issues
40 | gh-code-scanning-compat: true
41 | # Force 0 exit code to allow SARIF file generation
42 | # This will handover control about PR rejection to the GitHub side
43 | max-allowed-issues: 2147483647
44 |
45 | # Upload the SARIF file generated in the previous step
46 | - name: Upload SARIF results file
47 | uses: github/codeql-action/upload-sarif@v1
48 | with:
49 | sarif_file: results.sarif
50 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://t.me/ProductHuntTelegramBot)
2 | [](https://github.com/Crazy-Marvin/ProductHuntTelegramBot/actions/workflows/ci.yml)
3 | 
4 | [](https://github.com/Crazy-Marvin/ProductHuntTelegramBot/blob/trunk/LICENSE)
5 | [](https://github.com/Crazy-Marvin/ProductHuntTelegramBot/commits)
6 | [](https://github.com/Crazy-Marvin/ProductHuntTelegramBot/releases)
7 | [](https://github.com/Crazy-Marvin/ProductHuntTelegramBot/tags)
8 | [](https://github.com/Crazy-Marvin/ProductHuntTelegramBot/issues)
9 | [](https://github.com/Crazy-Marvin/ProductHuntTelegramBot/pulls)
10 | [](https://www.codacy.com/gh/Crazy-Marvin/ProductHuntTelegramBot/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Crazy-Marvin/ProductHuntTelegramBot&utm_campaign=Badge_Grade)
11 | [](https://python.org/)
12 | [](https://app.snyk.io/org/crazymarvin/project/e58b3418-2609-4731-b629-6812069fdb73)
13 | [](https://t.me/ProductHuntTelegramBot)
14 |
15 | # Product Hunt Telegram Bot
16 |
17 | This [bot](http://t.me/ProductHuntTelegramBot) shows you today's posts from [Product Hunt](https://www.producthunt.com/).
18 |
19 | 
20 |
21 | #### Commands
22 |
23 | start - This starts the bot 🚀
24 | daily - This sends all products of the day 🗣
25 | monthly - This sends all products of the month 🗣
26 | schedule - This lets you choose a schedule for automatic updates 🕰
27 | help - This sends you a help text 🆘
28 | contact - This allows contact ✍️
29 | feedback - This lets you give feedback 👺
30 |
31 | ### Requirements
32 |
33 | - Token from [@Botfather](https://telegram.me/botfather)
34 | - SSL certificate (I recommend [Let's Encrypt](https://letsencrypt.org/))
35 | - Webserver running [Python](https://www.python.org) (tested with [Apache](https://httpd.apache.org/) & [NGINX](https://www.nginx.com/) but others should work too)
36 | - API key from Product Hunt
37 | - Google Cloud service account credentials (JSON) for accessing Google Sheets API & Google Drive API
38 | - [Sentry](https://docs.sentry.io/platforms/python/) key (optional)
39 | - [Healthchecks](https://healthchecks.io/#php) URL (optional)
40 |
41 | ### Contributing
42 |
43 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
44 | Please make sure to update tests as appropriate.
45 | More details may be found in the [CONTRIUBTING.md](https://github.com/Crazy-Marvin/ProductHuntTelegramBot/tree/trunk/.github/CONTRIBUTING.md).
46 |
47 | ### License
48 |
49 | [MIT](https://choosealicense.com/licenses/mit/)
50 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Product_Hunt_bot.py:
--------------------------------------------------------------------------------
1 | import telebot
2 | import gspread
3 | import requests
4 | import threading
5 | import time
6 | import schedule
7 | import datetime
8 | from telebot.types import KeyboardButton, ReplyKeyboardMarkup
9 | from telebot import custom_filters
10 | from oauth2client.service_account import ServiceAccountCredentials
11 |
12 | dotenv.load_dotenv()
13 |
14 | # your Token from @Botfather
15 | API_KEY = os.getenv("API_KEY")
16 | my_id = os.getenv("my_id") # your personal chat ID
17 | analyst_id = os.getenv("analyst_id") # your analyst chat ID
18 | ph_auth = os.getenv("ph_auth") # your token for accessing the Product Hunt API
19 | # the place where your creds.json from Google is stored
20 | creds_location = os.getenv("creds_location")
21 | forms_url = os.getenv("forms_url") # your URL to the Google Forms for feedback
22 | # your URL to the Google Spreadsheet for analytics
23 | spreadsheet_url = os.getenv("spreadsheet_url")
24 |
25 | pod_img = "AgACAgUAAxkBAAMsYUtpwf4IweE0MYMGR9Vbpe1xOiEAAuStMRu77WBWjmCIZUpTv9oBAAMCAAN5AAMhBA"
26 | pom_img = "AgACAgUAAxkBAAIB9WFO1TnJhBFbYkS0O-VdaYA9UA3SAAJkrDEbzKd4Vq56YH6fcfZFAQADAgADeQADIQQ"
27 |
28 | scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/spreadsheets",
29 | "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
30 |
31 | creds = ServiceAccountCredentials.from_json_keyfile_name(creds_location, scope)
32 | client = gspread.authorize(creds)
33 |
34 | analytics_PRODUCT_HUNT_BOT = client.open(
35 | "ANALYTICS").worksheet("PRODUCT-HUNT_BOT")
36 | database = client.open("PRODUCT HUNT BOT DATABASE").worksheet("DATABASE")
37 |
38 | bot = telebot.TeleBot(API_KEY)
39 |
40 |
41 | @bot.message_handler(commands=['start'])
42 | def start(message):
43 |
44 | col = database.col_values(1)
45 |
46 | if str(message.chat.id) not in col:
47 | database.append_row([message.chat.id, 'daily/monthly'])
48 | analytics_PRODUCT_HUNT_BOT.update_acell('F10', str(
49 | len(database.col_values(1))-1).replace("'", " "))
50 |
51 | msg = '''
52 | Welcome to the [Product Hunt](https://www.producthunt.com/) Telegram bot\! 👶
53 |
54 | I can send you daily or monthly updates regarding posts on [Product Hunt](https://www.producthunt.com/)\. An opt\-out is possible if you would like to trigger me manually\.
55 |
56 | Send /help for more information\.
57 |
58 | Enjoy\! 🎉
59 | '''
60 | bot.send_message(message.chat.id, msg,
61 | parse_mode="MarkdownV2", disable_web_page_preview=True)
62 |
63 | start_count = analytics_PRODUCT_HUNT_BOT.acell('F3').value
64 | analytics_PRODUCT_HUNT_BOT.update_acell(
65 | 'F3', str(int(start_count)+1).replace("'", " "))
66 |
67 |
68 | @bot.message_handler(commands=["daily"])
69 | def pod(message):
70 |
71 | url = "https://api.producthunt.com/v1/posts"
72 |
73 | headers = {
74 | "Accept": "application/json",
75 | "Content-Type": "application/json",
76 | "Authorization": f"Bearer {ph_auth}",
77 | "Host": "api.producthunt.com"
78 | }
79 |
80 | posts, MSG = requests.get(url=url, headers=headers).json()['posts'], ""
81 |
82 | bot.send_photo(message.chat.id, pod_img)
83 |
84 | for count, post in enumerate(posts):
85 |
86 | if(count+1) == len(posts):
87 | bot.send_message(message.chat.id, MSG, parse_mode="HTML",
88 | disable_web_page_preview=True, disable_notification=True)
89 |
90 | elif (count + 1) % 10 == 0:
91 | bot.send_message(message.chat.id, MSG, parse_mode="HTML",
92 | disable_web_page_preview=True, disable_notification=True)
93 | MSG = ""
94 |
95 | MSG += f'➤ {post["name"]}: '
96 | MSG += f'{post["tagline"]}\n\n'
97 |
98 | END = "For more such amazing products, please visit our \
99 | website."
100 |
101 | bot.send_message(message.chat.id, END, parse_mode="HTML",
102 | disable_web_page_preview=True)
103 | ph_count = analytics_PRODUCT_HUNT_BOT.acell('F4').value
104 | analytics_PRODUCT_HUNT_BOT.update_acell(
105 | 'F4', str(int(ph_count)+1).replace("'", " "))
106 |
107 |
108 | @bot.message_handler(commands=["monthly"])
109 | def pom(message):
110 |
111 | month = datetime.datetime.today().month # TODO: Fix for Jan 1, 2022
112 | year = datetime.datetime.today().year
113 |
114 | url = f"https://api.producthunt.com/v1/posts/all?sort_by=votes_count&order=desc&search[featured_month]={month}&search[featured_year]={year}"
115 |
116 | headers = {
117 | "Accept": "application/json",
118 | "Content-Type": "application/json",
119 | "Authorization": f"Bearer {ph_auth}",
120 | "Host": "api.producthunt.com"
121 | }
122 |
123 | posts, MSG = requests.get(url=url, headers=headers).json()['posts'], ""
124 |
125 | bot.send_photo(message.chat.id, pom_img)
126 |
127 | for count, post in enumerate(posts):
128 |
129 | if(count+1) == len(posts):
130 | bot.send_message(message.chat.id, MSG, parse_mode="HTML",
131 | disable_web_page_preview=True, disable_notification=True)
132 |
133 | elif (count + 1) % 10 == 0:
134 | bot.send_message(message.chat.id, MSG, parse_mode="HTML",
135 | disable_web_page_preview=True, disable_notification=True)
136 | MSG = ""
137 |
138 | MSG += f'➤ {post["name"]}: '
139 | MSG += f'{post["tagline"]}\n\n'
140 |
141 | END = "For more such amazing products, please visit our \
142 | website."
143 |
144 | bot.send_message(message.chat.id, END, parse_mode="HTML",
145 | disable_web_page_preview=True)
146 | ph_count = analytics_PRODUCT_HUNT_BOT.acell('F5').value
147 | analytics_PRODUCT_HUNT_BOT.update_acell(
148 | 'F5', str(int(ph_count)+1).replace("'", " "))
149 |
150 |
151 | @bot.message_handler(commands=["schedule"])
152 | def sch(message):
153 |
154 | mark_up = ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
155 | B1 = KeyboardButton(text='DAILY UPDATES')
156 | B2 = KeyboardButton(text='MONTHLY UPDATES')
157 | B3 = KeyboardButton(text='DAILY & MONTHLY')
158 | B4 = KeyboardButton(text='MANUAL UPDATES')
159 |
160 | mark_up.row(B1, B2)
161 | mark_up.row(B3, B4)
162 |
163 | bot.send_message(
164 | message.chat.id, "How often would you like to recieve updates?", reply_markup=mark_up)
165 | sch_count = analytics_PRODUCT_HUNT_BOT.acell('F6').value
166 | analytics_PRODUCT_HUNT_BOT.update_acell(
167 | 'F6', str(int(sch_count)+1).replace("'", " "))
168 |
169 |
170 | @bot.message_handler(text=['DAILY UPDATES'])
171 | def text_filter(message):
172 |
173 | cell = database.find(str(message.chat.id))
174 | r, c = cell.row, cell.col+1
175 | database.update_cell(r, c, 'daily')
176 | bot.send_message(message.chat.id, "PREFERENCE: DAILY UPDATES")
177 |
178 |
179 | @bot.message_handler(text=['MONTHLY UPDATES'])
180 | def text_filter(message):
181 |
182 | cell = database.find(str(message.chat.id))
183 | r, c = cell.row, cell.col+1
184 | database.update_cell(r, c, 'monthly')
185 | bot.send_message(message.chat.id, "PREFERENCE: MONTHLY UPDATES")
186 |
187 |
188 | @bot.message_handler(text=['DAILY & MONTHLY'])
189 | def text_filter(message):
190 |
191 | cell = database.find(str(message.chat.id))
192 | r, c = cell.row, cell.col+1
193 | database.update_cell(r, c, 'daily/monthly')
194 | bot.send_message(message.chat.id, "PREFERENCE: DAILY & MONTHLY UPDATES")
195 |
196 |
197 | @bot.message_handler(text=['MANUAL UPDATES'])
198 | def text_filter(message):
199 |
200 | cell = database.find(str(message.chat.id))
201 | r, c = cell.row, cell.col+1
202 | database.update_cell(r, c, 'none')
203 | bot.send_message(message.chat.id, "PREFERENCE: MANUAL UPDATES")
204 |
205 |
206 | @bot.message_handler(commands=['contact'])
207 | def contact(message):
208 | contact_info = '''
209 | *CONTACT :*\n
210 | Telegram: https://t\.me/Marvin\_Marvin\n
211 | Mail: marvin@poopjournal\.rocks\n
212 | Issue: https://github\.com/Crazy\-Marvin/ProductHuntTelegramBot/issues\n
213 | Source: https://github\.com/Crazy\-Marvin/ProductHuntTelegramBot
214 | '''
215 | bot.send_message(message.chat.id, contact_info,
216 | parse_mode='MarkdownV2', disable_web_page_preview=True)
217 | contact_count = analytics_PRODUCT_HUNT_BOT.acell('F8').value
218 | analytics_PRODUCT_HUNT_BOT.update_acell(
219 | 'F8', str(int(contact_count)+1).replace("'", " "))
220 |
221 |
222 | @bot.message_handler(commands=['feedback'])
223 | def feedback(message):
224 |
225 | bot.send_message(message.chat.id, "Want to give us a feedback?\n\n\
226 | {forms_url} \n\nPlease fill out this Google Form☝🏻", disable_web_page_preview=True)
227 |
228 | feedback_count = analytics_PRODUCT_HUNT_BOT.acell('F7').value
229 | analytics_PRODUCT_HUNT_BOT.update_acell(
230 | 'F7', str(int(feedback_count)+1).replace("'", " "))
231 |
232 |
233 | @bot.message_handler(commands=['help'])
234 | def help(message):
235 | msg = '''
236 | Thanks for using the Product Hunt Telegram bot.
237 |
238 | After starting the bot with /start you will receive all Product Hunt posts daily. It is possible to opt-out or change the schedule with the /schedule command.
239 |
240 | Sending /ph will send you all posts from today again.
241 |
242 | If you would like to contact me send /contact.
243 | Feedback is very appreaciated by filling out a Google form which the bot will send you after sending him /feedback.
244 |
245 | Have fun! 🥳'''
246 |
247 | bot.send_message(message.chat.id, msg)
248 | help_count = analytics_PRODUCT_HUNT_BOT.acell('F9').value
249 | analytics_PRODUCT_HUNT_BOT.update_acell(
250 | 'F9', str(int(help_count)+1).replace("'", " "))
251 |
252 |
253 | @bot.message_handler(commands=['logs'])
254 | def logs(message):
255 |
256 | if message.chat.id == my_id or message.chat.id == analyst_id:
257 |
258 | bot.send_message(message.chat.id, f"Check out the *[ANALYTICS]{spreadsheet_url})* for the month\.",
259 | parse_mode="MarkdownV2", disable_web_page_preview=True)
260 |
261 |
262 | bot.add_custom_filter(custom_filters.TextMatchFilter())
263 |
264 |
265 | def monthly():
266 |
267 | if datetime.date.today() != 1:
268 | return
269 |
270 | month = datetime.datetime.today().month - 1 # TODO: Fix for Jan 1, 2022
271 | year = datetime.datetime.today().year
272 |
273 | url = f"https://api.producthunt.com/v1/posts/all?sort_by=votes_count&order=desc&search[featured_month]={month}&search[featured_year]={year}"
274 |
275 | headers = {
276 | "Accept": "application/json",
277 | "Content-Type": "application/json",
278 | "Authorization": f"Bearer {ph_auth}",
279 | "Host": "api.producthunt.com"
280 | }
281 |
282 | posts, MSG = requests.get(url=url, headers=headers).json()['posts'], ""
283 | users = database.get_all_records()
284 |
285 | for user in users:
286 |
287 | if user["Updates"] == "monthly" or user["Updates"] == "daily/monthly":
288 |
289 | chat_id = user["Chat Id"]
290 |
291 | bot.send_photo(chat_id, pom_img)
292 |
293 | for count, post in enumerate(posts):
294 |
295 | if(count+1) == len(posts):
296 | bot.send_message(chat_id, MSG, parse_mode="HTML",
297 | disable_web_page_preview=True, disable_notification=True)
298 |
299 | elif (count + 1) % 10 == 0:
300 | bot.send_message(chat_id, MSG, parse_mode="HTML",
301 | disable_web_page_preview=True, disable_notification=True)
302 | MSG = ""
303 |
304 | MSG += f'➤ {post["name"]}: '
305 | MSG += f'{post["tagline"]}\n\n'
306 |
307 | END = "For more such amazing products, please visit our website."
308 |
309 | bot.send_message(chat_id, END, parse_mode="HTML",
310 | disable_web_page_preview=True)
311 |
312 |
313 | def daily():
314 |
315 | url = "https://api.producthunt.com/v1/posts/"
316 |
317 | headers = {
318 | "Accept": "application/json",
319 | "Content-Type": "application/json",
320 | "Authorization": f"Bearer {ph_auth}",
321 | "Host": "api.producthunt.com"
322 | }
323 |
324 | posts, MSG = requests.get(url=url, headers=headers).json()['posts'], ""
325 | users = database.get_all_records()
326 |
327 | for user in users:
328 |
329 | if user["Updates"] == "daily" or user["Updates"] == "daily/monthly":
330 |
331 | chat_id = user["Chat Id"]
332 |
333 | bot.send_photo(chat_id, pod_img)
334 |
335 | for count, post in enumerate(posts):
336 |
337 | if(count+1) == len(posts):
338 | bot.send_message(chat_id, MSG, parse_mode="HTML",
339 | disable_web_page_preview=True, disable_notification=True)
340 |
341 | elif (count + 1) % 10 == 0:
342 | bot.send_message(chat_id, MSG, parse_mode="HTML",
343 | disable_web_page_preview=True, disable_notification=True)
344 | MSG = ""
345 |
346 | MSG += f'➤ {post["name"]}: '
347 | MSG += f'{post["tagline"]}\n\n'
348 |
349 | END = "For more such amazing products, please visit our website."
350 |
351 | bot.send_message(chat_id, END, parse_mode="HTML",
352 | disable_web_page_preview=True)
353 |
354 |
355 | schedule.every().day.at("00:00").do(daily)
356 | schedule.every().day.at("12:00").do(monthly)
357 |
358 | # TODO: Create a separate script and host it as a main thread on server for better performance 🤔
359 |
360 |
361 | def thrd():
362 | while True:
363 | schedule.run_pending()
364 | time.sleep(5)
365 |
366 |
367 | t = threading.Thread(target=thrd)
368 |
369 | t.start()
370 | bot.polling()
371 |
--------------------------------------------------------------------------------